"use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard")["default"];

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.create = create;
exports["default"] = void 0;

var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));

var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));

var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));

var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));

var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));

var _createSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/createSuper"));

var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));

var _react = _interopRequireWildcard(require("react"));

var _classnames = _interopRequireDefault(require("classnames"));

var _omit = _interopRequireDefault(require("lodash/omit"));

var _warning = _interopRequireDefault(require("../_util/warning"));

var _FormItem = _interopRequireDefault(require("./FormItem"));

var _constants = require("./constants");

var _form = require("../rc-components/form");

var _createDOMForm = _interopRequireDefault(require("../rc-components/form/createDOMForm"));

var _PureRenderMixin = _interopRequireDefault(require("../rc-components/util/PureRenderMixin"));

var _enum = require("./enum");

var _ConfigContext = _interopRequireDefault(require("../config-provider/ConfigContext"));

var _FormContext = require("./FormContext");

function create() {
  var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  return (0, _createDOMForm["default"])((0, _objectSpread2["default"])((0, _objectSpread2["default"])({
    fieldNameProp: 'id'
  }, options), {}, {
    fieldMetaProp: _constants.FIELD_META_PROP,
    fieldDataProp: _constants.FIELD_DATA_PROP
  }));
}

var Form = /*#__PURE__*/function (_Component) {
  (0, _inherits2["default"])(Form, _Component);

  var _super = (0, _createSuper2["default"])(Form);

  function Form(props) {
    var _this;

    (0, _classCallCheck2["default"])(this, Form);
    _this = _super.call(this, props);
    (0, _warning["default"])(!props.form, 'It is unnecessary to pass `form` to `Form`');
    return _this;
  }

  (0, _createClass2["default"])(Form, [{
    key: "shouldComponentUpdate",
    value: function shouldComponentUpdate() {
      for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
        args[_key] = arguments[_key];
      }

      return _PureRenderMixin["default"].shouldComponentUpdate.apply(this, args);
    }
  }, {
    key: "render",
    value: function render() {
      var _classNames;

      var _this$props = this.props,
          customizePrefixCls = _this$props.prefixCls,
          hideRequiredMark = _this$props.hideRequiredMark,
          _this$props$className = _this$props.className,
          className = _this$props$className === void 0 ? '' : _this$props$className,
          layout = _this$props.layout;
      var getPrefixCls = this.context.getPrefixCls;
      var prefixCls = getPrefixCls('form', customizePrefixCls);
      var formClassName = (0, _classnames["default"])(prefixCls, (_classNames = {}, (0, _defineProperty2["default"])(_classNames, "".concat(prefixCls, "-").concat(layout), layout), (0, _defineProperty2["default"])(_classNames, "".concat(prefixCls, "-hide-required-mark"), hideRequiredMark), _classNames), className);
      var formProps = (0, _omit["default"])(this.props, ['prefixCls', 'className', 'layout', 'form', 'hideRequiredMark']);
      return /*#__PURE__*/_react["default"].createElement(_FormContext.FormContextProvider, {
        vertical: layout === 'vertical',
        getPrefixCls: getPrefixCls
      }, /*#__PURE__*/_react["default"].createElement("form", (0, _extends2["default"])({}, formProps, {
        className: formClassName
      })));
    }
  }], [{
    key: "contextType",
    get: function get() {
      return _ConfigContext["default"];
    }
  }]);
  return Form;
}(_react.Component);

exports["default"] = Form;
Form.displayName = 'Form';
Form.defaultProps = {
  layout: _enum.FormLayout.horizontal,
  hideRequiredMark: false,
  onSubmit: function onSubmit(e) {
    e.preventDefault();
  }
};
Form.Item = _FormItem["default"];
Form.createFormField = _form.createFormField;
Form.create = create;
//# sourceMappingURL=Form.js.map
