import _extends from "@babel/runtime/helpers/extends";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _inherits from "@babel/runtime/helpers/inherits";
import _createSuper from "@babel/runtime/helpers/createSuper";
import _objectSpread from "@babel/runtime/helpers/objectSpread2";
import React, { Component } from 'react';
import classNames from 'classnames';
import omit from 'lodash/omit';
import warning from '../_util/warning';
import FormItem from './FormItem';
import { FIELD_DATA_PROP, FIELD_META_PROP } from './constants';
import { createFormField } from '../rc-components/form';
import createDOMForm from '../rc-components/form/createDOMForm';
import PureRenderMixin from '../rc-components/util/PureRenderMixin';
import { FormLayout } from './enum';
import ConfigContext from '../config-provider/ConfigContext';
import { FormContextProvider } from './FormContext';
export function create() {
  var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  return createDOMForm(_objectSpread(_objectSpread({
    fieldNameProp: 'id'
  }, options), {}, {
    fieldMetaProp: FIELD_META_PROP,
    fieldDataProp: FIELD_DATA_PROP
  }));
}

var Form = /*#__PURE__*/function (_Component) {
  _inherits(Form, _Component);

  var _super = _createSuper(Form);

  function Form(props) {
    var _this;

    _classCallCheck(this, Form);

    _this = _super.call(this, props);
    warning(!props.form, 'It is unnecessary to pass `form` to `Form`');
    return _this;
  }

  _createClass(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.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 = classNames(prefixCls, (_classNames = {}, _defineProperty(_classNames, "".concat(prefixCls, "-").concat(layout), layout), _defineProperty(_classNames, "".concat(prefixCls, "-hide-required-mark"), hideRequiredMark), _classNames), className);
      var formProps = omit(this.props, ['prefixCls', 'className', 'layout', 'form', 'hideRequiredMark']);
      return /*#__PURE__*/React.createElement(FormContextProvider, {
        vertical: layout === 'vertical',
        getPrefixCls: getPrefixCls
      }, /*#__PURE__*/React.createElement("form", _extends({}, formProps, {
        className: formClassName
      })));
    }
  }], [{
    key: "contextType",
    get: function get() {
      return ConfigContext;
    }
  }]);

  return Form;
}(Component);

export { Form as default };
Form.displayName = 'Form';
Form.defaultProps = {
  layout: FormLayout.horizontal,
  hideRequiredMark: false,
  onSubmit: function onSubmit(e) {
    e.preventDefault();
  }
};
Form.Item = FormItem;
Form.createFormField = createFormField;
Form.create = create;
//# sourceMappingURL=Form.js.map
