text: "use strict";
  
  Object.defineProperty(exports, "__esModule", {
    value: true
  });
  exports["default"] = void 0;
  
  var React = _interopRequireWildcard(require("react"));
  
  var ReactDOM = _interopRequireWildcard(require("react-dom"));
  
  var PropTypes = _interopRequireWildcard(require("prop-types"));
  
  var _classnames = _interopRequireDefault(require("classnames"));
  
  var _rcAnimate = _interopRequireDefault(require("rc-animate"));
  
  var _constants = require("./constants");
  
  var _row = _interopRequireDefault(require("../grid/row"));
  
  var _col = _interopRequireDefault(require("../grid/col"));
  
  var _icon = _interopRequireDefault(require("../icon"));
  
  var _configProvider = require("../config-provider");
  
  var _warning = _interopRequireDefault(require("../_util/warning"));
  
  var _type = require("../_util/type");
  
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
  
  function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj["default"] = obj; return newObj; } }
  
  function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  
  function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
  
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
  
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  
  function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  
  function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  
  function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  
  function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  
  function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  
  function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
  
  function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }
  
  function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }
  
  function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }
  
  var ValidateStatuses = (0, _type.tuple)('success', 'warning', 'error', 'validating', '');
  
  function intersperseSpace(list) {
    return list.reduce(function (current, item) {
      return [].concat(_toConsumableArray(current), [' ', item]);
    }, []).slice(1);
  }
  
  var FormItem =
  /*#__PURE__*/
  function (_React$Component) {
    _inherits(FormItem, _React$Component);
  
    function FormItem() {
      var _this;
  
      _classCallCheck(this, FormItem);
  
      _this = _possibleConstructorReturn(this, _getPrototypeOf(FormItem).apply(this, arguments));
      _this.helpShow = false;
  
      _this.onHelpAnimEnd = function (_key, helpShow) {
        _this.helpShow = helpShow;
  
        if (!helpShow) {
          _this.setState({});
        }
      }; // Resolve duplicated ids bug between different forms
      // https://github.com/ant-design/ant-design/issues/7351
  
  
      _this.onLabelClick = function (e) {
        var label = _this.props.label;
  
        var id = _this.props.id || _this.getId();
  
        if (!id) {
          return;
        }
  
        var controls = document.querySelectorAll("[id=\"".concat(id, "\"]"));
  
        if (controls.length !== 1) {
          // Only prevent in default situation
          // Avoid preventing event in `label={<a href="xx">link</a>}``
          if (typeof label === 'string') {
            e.preventDefault();
          }
  
          var formItemNode = ReactDOM.findDOMNode(_assertThisInitialized(_assertThisInitialized(_this)));
          var control = formItemNode.querySelector("[id=\"".concat(id, "\"]"));
  
          if (control && control.focus) {
            control.focus();
          }
        }
      };
  
      _this.renderFormItem = function (_ref) {
        var _itemClassName;
  
        var getPrefixCls = _ref.getPrefixCls;
        var _this$props = _this.props,
            customizePrefixCls = _this$props.prefixCls,
            style = _this$props.style,
            colon = _this$props.colon,
            className = _this$props.className;
        var prefixCls = getPrefixCls('form', customizePrefixCls);
  
        var children = _this.renderChildren(prefixCls);
  
        var itemClassName = (_itemClassName = {}, _defineProperty(_itemClassName, "".concat(prefixCls, "-item"), true), _defineProperty(_itemClassName, "".concat(prefixCls, "-item-with-help"), _this.helpShow), _defineProperty(_itemClassName, "".concat(prefixCls, "-item-no-colon"), !colon), _defineProperty(_itemClassName, "".concat(className), !!className), _itemClassName);
        return React.createElement(_row["default"], {
          className: (0, _classnames["default"])(itemClassName),
          style: style
        }, children);
      };
  
      return _this;
    }
  
    _createClass(FormItem, [{
      key: "componentDidMount",
      value: function componentDidMount() {
        (0, _warning["default"])(this.getControls(this.props.children, true).length <= 1, '`Form.Item` cannot generate `validateStatus` and `help` automatically, ' + 'while there are more than one `getFieldDecorator` in it.');
      }
    }, {
      key: "getHelpMessage",
      value: function getHelpMessage() {
        var help = this.props.help;
  
        if (help === undefined && this.getOnlyControl()) {
          var errors = this.getField().errors;
  
          if (errors) {
            return intersperseSpace(errors.map(function (e, index) {
              var node = null;
  
              if (React.isValidElement(e)) {
                node = e;
              } else if (React.isValidElement(e.message)) {
                node = e.message;
              }
  
              return node ? React.cloneElement(node, {
                key: index
              }) : e.message;
            }));
          }
  
          return '';
        }
  
        return help;
      }
    }, {
      key: "getControls",
      value: function getControls(children, recursively) {
        var controls = [];
        var childrenArray = React.Children.toArray(children);
  
        for (var i = 0; i < childrenArray.length; i++) {
          if (!recursively && controls.length > 0) {
            break;
          }
  
          var child = childrenArray[i];
  
          if (child.type && (child.type === FormItem || child.type.displayName === 'FormItem')) {
            continue;
          }
  
          if (!child.props) {
            continue;
          }
  
          if (_constants.FIELD_META_PROP in child.props) {
            // And means FIELD_DATA_PROP in child.props, too.
            controls.push(child);
          } else if (child.props.children) {
            controls = controls.concat(this.getControls(child.props.children, recursively));
          }
        }
  
        return controls;
      }
    }, {
      key: "getOnlyControl",
      value: function getOnlyControl() {
        var child = this.getControls(this.props.children, false)[0];
        return child !== undefined ? child : null;
      }
    }, {
      key: "getChildProp",
      value: function getChildProp(prop) {
        var child = this.getOnlyControl();
        return child && child.props && child.props[prop];
      }
    }, {
      key: "getId",
      value: function getId() {
        return this.getChildProp('id');
      }
    }, {
      key: "getMeta",
      value: function getMeta() {
        return this.getChildProp(_constants.FIELD_META_PROP);
      }
    }, {
      key: "getField",
      value: function getField() {
        return this.getChildProp(_constants.FIELD_DATA_PROP);
      }
    }, {
      key: "renderHelp",
      value: function renderHelp(prefixCls) {
        var help = this.getHelpMessage();
        var children = help ? React.createElement("div", {
          className: "".concat(prefixCls, "-explain"),
          key: "help"
        }, help) : null;
  
        if (children) {
          this.helpShow = !!children;
        }
  
        return React.createElement(_rcAnimate["default"], {
          transitionName: "show-help",
          component: "",
          transitionAppear: true,
          key: "help",
          onEnd: this.onHelpAnimEnd
        }, children);
      }
    }, {
      key: "renderExtra",
      value: function renderExtra(prefixCls) {
        var extra = this.props.extra;
        return extra ? React.createElement("div", {
          className: "".concat(prefixCls, "-extra")
        }, extra) : null;
      }
    }, {
      key: "getValidateStatus",
      value: function getValidateStatus() {
        var onlyControl = this.getOnlyControl();
  
        if (!onlyControl) {
          return '';
        }
  
        var field = this.getField();
  
        if (field.validating) {
          return 'validating';
        }
  
        if (field.errors) {
          return 'error';
        }
  
        var fieldValue = 'value' in field ? field.value : this.getMeta().initialValue;
  
        if (fieldValue !== undefined && fieldValue !== null && fieldValue !== '') {
          return 'success';
        }
  
        return '';
      }
    }, {
      key: "renderValidateWrapper",
      value: function renderValidateWrapper(prefixCls, c1, c2, c3) {
        var props = this.props;
        var onlyControl = this.getOnlyControl;
        var validateStatus = props.validateStatus === undefined && onlyControl ? this.getValidateStatus() : props.validateStatus;
        var classes = "".concat(prefixCls, "-item-control");
  
        if (validateStatus) {
          classes = (0, _classnames["default"])("".concat(prefixCls, "-item-control"), {
            'has-feedback': props.hasFeedback || validateStatus === 'validating',
            'has-success': validateStatus === 'success',
            'has-warning': validateStatus === 'warning',
            'has-error': validateStatus === 'error',
            'is-validating': validateStatus === 'validating'
          });
        }
  
        var iconType = '';
  
        switch (validateStatus) {
          case 'success':
            iconType = 'check-circle';
            break;
  
          case 'warning':
            iconType = 'exclamation-circle';
            break;
  
          case 'error':
            iconType = 'close-circle';
            break;
  
          case 'validating':
            iconType = 'loading';
            break;
  
          default:
            iconType = '';
            break;
        }
  
        var icon = props.hasFeedback && iconType ? React.createElement("span", {
          className: "".concat(prefixCls, "-item-children-icon")
        }, React.createElement(_icon["default"], {
          type: iconType,
          theme: iconType === 'loading' ? 'outlined' : 'filled'
        })) : null;
        return React.createElement("div", {
          className: classes
        }, React.createElement("span", {
          className: "".concat(prefixCls, "-item-children")
        }, c1, icon), c2, c3);
      }
    }, {
      key: "renderWrapper",
      value: function renderWrapper(prefixCls, children) {
        var wrapperCol = this.props.wrapperCol;
        var className = (0, _classnames["default"])("".concat(prefixCls, "-item-control-wrapper"), wrapperCol && wrapperCol.className);
        return React.createElement(_col["default"], _extends({}, wrapperCol, {
          className: className,
          key: "wrapper"
        }), children);
      }
    }, {
      key: "isRequired",
      value: function isRequired() {
        var required = this.props.required;
  
        if (required !== undefined) {
          return required;
        }
  
        if (this.getOnlyControl()) {
          var meta = this.getMeta() || {};
          var validate = meta.validate || [];
          return validate.filter(function (item) {
            return !!item.rules;
          }).some(function (item) {
            return item.rules.some(function (rule) {
              return rule.required;
            });
          });
        }
  
        return false;
      }
    }, {
      key: "renderLabel",
      value: function renderLabel(prefixCls) {
        var _this$props2 = this.props,
            label = _this$props2.label,
            labelCol = _this$props2.labelCol,
            colon = _this$props2.colon,
            id = _this$props2.id;
        var context = this.context;
        var required = this.isRequired();
        var labelColClassName = (0, _classnames["default"])("".concat(prefixCls, "-item-label"), labelCol && labelCol.className);
        var labelClassName = (0, _classnames["default"])(_defineProperty({}, "".concat(prefixCls, "-item-required"), required));
        var labelChildren = label; // Keep label is original where there should have no colon
  
        var haveColon = colon && !context.vertical; // Remove duplicated user input colon
  
        if (haveColon && typeof label === 'string' && label.trim() !== '') {
          labelChildren = label.replace(/[：|:]\s*$/, '');
        }
  
        return label ? React.createElement(_col["default"], _extends({}, labelCol, {
          className: labelColClassName,
          key: "label"
        }), React.createElement("label", {
          htmlFor: id || this.getId(),
          className: labelClassName,
          title: typeof label === 'string' ? label : '',
          onClick: this.onLabelClick
        }, labelChildren)) : null;
      }
    }, {
      key: "renderChildren",
      value: function renderChildren(prefixCls) {
        var children = this.props.children;
        return [this.renderLabel(prefixCls), this.renderWrapper(prefixCls, this.renderValidateWrapper(prefixCls, children, this.renderHelp(prefixCls), this.renderExtra(prefixCls)))];
      }
    }, {
      key: "render",
      value: function render() {
        return React.createElement(_configProvider.ConfigConsumer, null, this.renderFormItem);
      }
    }]);
  
    return FormItem;
  }(React.Component);
  
  exports["default"] = FormItem;
  FormItem.defaultProps = {
    hasFeedback: false,
    colon: true
  };
  FormItem.propTypes = {
    prefixCls: PropTypes.string,
    label: PropTypes.oneOfType([PropTypes.string, PropTypes.node]),
    labelCol: PropTypes.object,
    help: PropTypes.oneOfType([PropTypes.node, PropTypes.bool]),
    validateStatus: PropTypes.oneOf(ValidateStatuses),
    hasFeedback: PropTypes.bool,
    wrapperCol: PropTypes.object,
    className: PropTypes.string,
    id: PropTypes.string,
    children: PropTypes.node,
    colon: PropTypes.bool
  };
  FormItem.contextTypes = {
    vertical: PropTypes.bool
  };