function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }

var _excluded = ["colLayout", "formItemLayout"];

function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }

function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }

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 _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 _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); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }

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 } }); Object.defineProperty(subClass, "prototype", { writable: false }); 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 _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }

function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }

function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }

function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }

function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }

// @ts-nocheck
import React, { Component, Fragment } from "react";
import moment from 'moment';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import Form from '../compatible-form'; // import '@ant-design/compatible/assets/index.css';

import Row from "antd/es/row";
import Col from "antd/es/col";
import Input from "antd/es/input";
import Select from "antd/es/select";
import DatePicker from "antd/es/date-picker";
import InputNumber from "antd/es/input-number";
import TreeSelect from "antd/es/tree-select";
import Cascader from "antd/es/cascader";
import Button from "antd/es/button";
import Upload from "antd/es/upload";
import Radio from "antd/es/radio";
import Checkbox from "antd/es/checkbox";
import TimePicker from "antd/es/time-picker";
import AutoComplete from "antd/es/auto-complete";
import Slider from "antd/es/slider";
import Divider from "antd/es/divider";
import Rate from "antd/es/rate";
import { PlusOutlined, UploadOutlined } from '@fishx/icons';
import PopEdit from '../pop-edit';
import LocaleReceiver from 'antd/es/locale-provider/LocaleReceiver';
import defaultLocale from "antd/es/locale/zh_CN";

var judgeShowTime = function judgeShowTime(values, id) {
  var targetItem = values.find(function (v) {
    return v.attrId === id;
  }) || {};

  if (Object.keys(targetItem).length) {
    var attrValue = targetItem.attrValue;
    return attrValue.indexOf(' ') > -1 && attrValue.split(' ').length === 2;
  }

  return false;
};

var transFishformToFdx = function transFishformToFdx(format, values, id) {
  var showTime = judgeShowTime(values, id);
  var fdxFormat = format.toUpperCase();
  fdxFormat = fdxFormat.replace('II', 'mm');
  fdxFormat = fdxFormat.replace(':MM', ':mm'); // #98

  fdxFormat = fdxFormat.replace('SS', 'ss');
  if (fdxFormat.split(' ').length > 1) return fdxFormat;
  return showTime ? "".concat(fdxFormat, " HH:mm:ss") : fdxFormat;
};

var FormItem = Form.Item;
var Option = Select.Option;
var TextArea = Input.TextArea;
var COMMONRule = {
  required: true,
  msg: 'Required'
};
var COMMONDATE_RULE = {
  type: 'object',
  required: true,
  msg: 'Required'
};
var COMMONARRAY_RULE = {
  type: 'array',
  required: true,
  msg: 'Required'
}; // 默认表单一行一组控件

var ColLayout = {
  xs: 24,
  sm: 24,
  md: 24,
  xl: 24
}; // 默认label和输入控件的样式布局

var FormItemLayout = {
  labelCol: {
    span: 7
  },
  wrapperCol: {
    span: 17
  }
};

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

  var _super = _createSuper(DynamicAttribute);

  function DynamicAttribute(_props) {
    var _this;

    _classCallCheck(this, DynamicAttribute);

    _this = _super.call(this, _props);

    _this.appendAddition = function () {
      var additionRegistry = _this.props.additionRegistry;
      var registries = {};

      if (!additionRegistry.length) {
        return registries;
      }

      additionRegistry.forEach(function (reg) {
        registries[reg.type] = _this.renderOther;
      });
      return registries;
    };

    _this.getFieldsValue = function (e) {
      if (e) {
        e.preventDefault();
      }

      var _this$props = _this.props,
          form = _this$props.form,
          layout = _this$props.layout,
          initValues = _this$props.initValues,
          formProps = _this$props.formProps;
      var onSubmit = formProps.onSubmit;

      if (onSubmit) {
        onSubmit(form);
        return;
      }

      var values = {};
      var valid = true;
      form.validateFields(function (err, fieldsValue) {
        if (err) {
          valid = false;
          return;
        }

        Object.keys(fieldsValue).forEach(function (key) {
          var value = fieldsValue[key];

          if (moment.isMoment(value)) {
            var targetItem = layout.find(function (v) {
              return v.id === key;
            });
            var id = targetItem.id,
                _targetItem$format = targetItem.format,
                format = _targetItem$format === void 0 ? 'YYYY-MM-DD' : _targetItem$format;
            var realFormat = transFishformToFdx(format, initValues, id);
            values[key] = value.format(realFormat);
          } else values[key] = value;
        });
      });
      return valid ? values : false;
    };

    _this.resetFields = function () {
      var resetFields = _this.props.form.resetFields;
      resetFields();
    };

    _this.judgeIfContain = function (item, currentValue, type) {
      var containFlag = true;
      if (type === 'multiselect' && !Array.isArray(currentValue)) currentValue = currentValue.split("|");
      var getFieldValue = _this.props.form.getFieldValue;
      var bindctrl = item.bindctrl,
          _item$data = item.data,
          data = _item$data === void 0 ? [] : _item$data;
      var ctrlVal = getFieldValue(bindctrl);
      var options = data.filter(function (v) {
        return v.bindTo === ctrlVal;
      });

      if (Array.isArray(currentValue)) {
        var optionValues = options.map(function (v) {
          return v.value;
        });

        if (currentValue.some(function (v) {
          return !optionValues.includes(v);
        })) {
          containFlag = false;
        }
      } else if (!options.some(function (v) {
        return v.value === currentValue;
      })) {
        containFlag = false;
      }

      return containFlag;
    };

    _this.handleMultiValues = function (type, value) {
      if (type === 'multiselect') {
        if (!value) return [];
        return value.split("|");
      }

      if (type === 'datetimepicker') {
        return value ? moment(value) : null;
      }

      return value;
    };

    _this.handleInit = function (item) {
      var initValues = _this.props.initValues;
      var id = item.id,
          type = item.type,
          bindctrl = item.bindctrl;

      if (initValues.length > 0) {
        var targetItem = initValues.find(function (v) {
          return v.attrId === id;
        }) || {};

        if (Object.keys(targetItem).length) {
          if (bindctrl) {
            if (targetItem.attrValue) {
              if (!_this.judgeIfContain(item, targetItem.attrValue, type)) {
                return type === 'multiselect' ? [] : null;
              }
            }
          }

          return _this.handleMultiValues(type, targetItem.attrValue);
        }

        return type === 'multiselect' ? [] : null;
      }

      return type === 'multiselect' ? [] : null;
    };

    _this.generateSelectBefore = function (data, restProps, id) {
      var getFieldDecorator = _this.props.form.getFieldDecorator;
      var initValues = _this.props.initValues;
      var targetItem = initValues.find(function (v) {
        return v.attrId === id;
      }) || {}; // return (
      // <Form.Item initialValues={{prefixProtocol:targetItem.attrValue}}>
      // <Select className="dynamic-select" style={{ width: 90 }} {...restProps}>
      // {data.length !== 0 && data.map((item, index) => <Option value={item} key={`protocol-${index}`}>{item}</Option>)}
      // </Select>
      // </Form.Item>
      // )

      return getFieldDecorator('prefixProtocol', {
        initialValue: targetItem.attrValue
      })( /*#__PURE__*/React.createElement(Select, _extends({
        className: "dynamic-select",
        style: {
          width: 90
        }
      }, restProps), data.length !== 0 && data.map(function (item, index) {
        return /*#__PURE__*/React.createElement(Option, {
          value: item,
          key: "protocol-".concat(index)
        }, item);
      })));
    };

    _this.generateSelectAfter = function (data, restProps, id) {
      var getFieldDecorator = _this.props.form.getFieldDecorator;
      var initValues = _this.props.initValues;
      var targetItem = initValues.find(function (v) {
        return v.attrId === id;
      }) || {};
      return getFieldDecorator('suffixSite', {
        initialValue: targetItem.attrValue
      })( /*#__PURE__*/React.createElement(Select, _extends({
        className: "dynamic-select",
        style: {
          width: 80
        }
      }, restProps), data.length !== 0 && data.map(function (item, index) {
        return /*#__PURE__*/React.createElement(Option, {
          value: item,
          key: "site-".concat(index)
        }, item);
      })));
    };

    _this.renderOptions = function (item) {
      var bindctrl = item.bindctrl,
          data = item.data,
          id = item.id,
          type = item.type;
      var _this$props$form = _this.props.form,
          getFieldValue = _this$props$form.getFieldValue,
          resetFields = _this$props$form.resetFields;
      var options = data;

      if (bindctrl) {
        var ctrlVal = getFieldValue(bindctrl);

        if (ctrlVal) {
          options = data.filter(function (v) {
            return v.bindTo === ctrlVal;
          });
        } // 若当前选择项不全部属于bindctrl，需要清空选择项


        var currentValue = getFieldValue(id);

        if (currentValue) {
          if (!_this.judgeIfContain(item, currentValue, type)) {
            resetFields([id]);
          }
        }
      }

      return options.map(function (iem) {
        return /*#__PURE__*/React.createElement(Option, {
          value: iem.value,
          key: "".concat(bindctrl, "_").concat(iem.value, "_").concat(iem.name)
        }, iem.name);
      });
    };

    _this.renderItem = function (item, index) {
      var formProps = _this.props.formProps;
      var registry = _this.state.registry;
      var _formProps$colLayout = formProps.colLayout,
          colLayout = _formProps$colLayout === void 0 ? ColLayout : _formProps$colLayout,
          _formProps$formItemLa = formProps.formItemLayout,
          formItemLayout = _formProps$formItemLa === void 0 ? FormItemLayout : _formProps$formItemLa;
      var type = item.type,
          label = item.label,
          _item$colLayout = item.colLayout,
          itemColLayout = _item$colLayout === void 0 ? colLayout : _item$colLayout,
          _item$formItemLayout = item.formItemLayout,
          itemFormLayout = _item$formItemLayout === void 0 ? formItemLayout : _item$formItemLayout,
          _item$ctrlProps = item.ctrlProps,
          ctrlProps = _item$ctrlProps === void 0 ? {} : _item$ctrlProps;
      var _ctrlProps$readOnly = ctrlProps.readOnly,
          readOnly = _ctrlProps$readOnly === void 0 ? false : _ctrlProps$readOnly;
      var renderFunc = registry[type];

      var relColLayout = _objectSpread({}, itemColLayout);

      if (item.type === 'hidden') relColLayout = {
        span: 0
      }; // #98 隐藏 FormItem 同时 需要隐藏包裹 FormItem 的 Col

      return /*#__PURE__*/React.createElement(Col, _extends({
        key: "dynamic_".concat(index)
      }, relColLayout), type === 'divider' ? /*#__PURE__*/React.createElement(Divider, null) : /*#__PURE__*/React.createElement(FormItem, _extends({
        className: classNames('dynamic-form-item', {
          'readOnlyItem': readOnly === true,
          'hiddenItem': type === 'hidden'
        })
      }, itemFormLayout, {
        label: label
      }), renderFunc(item, index)));
    };

    _this.renderCommonAttrs = function (item) {
      var onChange = _this.props.onChange;
      var _item$ctrlProps2 = item.ctrlProps,
          ctrlProps = _item$ctrlProps2 === void 0 ? {} : _item$ctrlProps2;

      var params = _objectSpread({}, ctrlProps);

      if (onChange) {
        params.onChange = function (value) {
          onChange(item.id, value);
        };
      }

      return params;
    };

    _this.renderSubmit = function (item) {
      var _item$ctrlProps3 = item.ctrlProps,
          ctrlProps = _item$ctrlProps3 === void 0 ? {} : _item$ctrlProps3,
          _item$btnProps = item.btnProps,
          btnProps = _item$btnProps === void 0 ? {} : _item$btnProps;
      var _ctrlProps$readOnly2 = ctrlProps.readOnly,
          readOnly = _ctrlProps$readOnly2 === void 0 ? false : _ctrlProps$readOnly2;
      var restProps = {};
      if (readOnly) restProps.disabled = true;
      var _btnProps$label = btnProps.label,
          label = _btnProps$label === void 0 ? 'submit' : _btnProps$label;
      return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(Button, _extends({
        type: "primary",
        htmlType: "submit"
      }, restProps), label));
    };

    _this.filterRules = function () {
      var rules = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
      rules.forEach(function (rule) {
        if (rule.pattern !== undefined) {
          var flag = rule.flag || 'i';
          rule.pattern = new RegExp(rule.pattern, flag);
        }
      });
      return rules;
    };

    _this.renderInput = function (item) {
      var getFieldDecorator = _this.props.form.getFieldDecorator;
      var _item$datarule = item.datarule,
          datarule = _item$datarule === void 0 ? '' : _item$datarule,
          id = item.id,
          required = item.required,
          type = item.type,
          _item$rules = item.rules,
          rules = _item$rules === void 0 ? [] : _item$rules;

      var rulesDefault = _this.filterRules(rules);

      if (required) rulesDefault.unshift(COMMONRule);
      var key = "length";

      if (datarule.length > 0 && datarule.indexOf(key) > -1) {
        var index = datarule.indexOf(key) + key.length;
        var maxmin = datarule.substring(index, datarule.length);
        var min = maxmin.substring(1, maxmin.indexOf("~"));
        var max = maxmin.substring(maxmin.indexOf("~") + 1, maxmin.length - 1);
        if (min !== '') rulesDefault.unshift({
          min: parseInt(min, 10)
        });
        if (max !== '') rulesDefault.unshift({
          max: parseInt(max, 10)
        });
      }

      if (type === 'textarea') {
        return getFieldDecorator(id, {
          initialValue: _this.handleInit(item),
          rules: rulesDefault
        })( /*#__PURE__*/React.createElement(TextArea, _this.renderCommonAttrs(item)));
      }

      if (type === 'text') {
        return getFieldDecorator(id, {
          initialValue: _this.handleInit(item),
          rules: rulesDefault
        })( /*#__PURE__*/React.createElement(Input, _this.renderCommonAttrs(item)));
      }

      if (type === 'password') {
        return getFieldDecorator(id, {
          initialValue: _this.handleInit(item),
          rules: rulesDefault
        })( /*#__PURE__*/React.createElement(Input.Password, _this.renderCommonAttrs(item)));
      } else {
        return getFieldDecorator(id, {
          initialValue: _this.handleInit(item)
        })( /*#__PURE__*/React.createElement(Input, null));
      }
    };

    _this.renderOther = function (item) {
      var _this$props2 = _this.props,
          getFieldDecorator = _this$props2.form.getFieldDecorator,
          additionRegistry = _this$props2.additionRegistry;
      var required = item.required,
          id = item.id,
          _item$rules2 = item.rules,
          rules = _item$rules2 === void 0 ? [] : _item$rules2;

      var rulesDefault = _this.filterRules(rules);

      if (required) rulesDefault.unshift(COMMONDATE_RULE);
      var reg = additionRegistry.find(function (data) {
        return data.type === id;
      });
      return getFieldDecorator(id, {
        initialValue: _this.handleInit(item),
        rules: rulesDefault
      })(reg.getComp());
    };

    _this.renderNumber = function (item) {
      var getFieldDecorator = _this.props.form.getFieldDecorator;
      var required = item.required,
          id = item.id,
          _item$rules3 = item.rules,
          rules = _item$rules3 === void 0 ? [] : _item$rules3;

      var rulesDefault = _this.filterRules(rules);

      if (required) rulesDefault.unshift(COMMONDATE_RULE);
      return getFieldDecorator(id, {
        initialValue: _this.handleInit(item),
        rules: rulesDefault
      })( /*#__PURE__*/React.createElement(InputNumber, _extends({
        className: "dynamic-input-number"
      }, _this.renderCommonAttrs(item))));
    };

    _this.getUploadBtn = function (item, restProps, locale) {
      var _item$ctrlProps4 = item.ctrlProps,
          ctrlProps = _item$ctrlProps4 === void 0 ? {} : _item$ctrlProps4;
      var listType = ctrlProps.listType;

      if (listType === 'picture-card') {
        return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(PlusOutlined, null), /*#__PURE__*/React.createElement("div", {
          className: "ant-upload-text"
        }, locale.upload));
      }

      return /*#__PURE__*/React.createElement(Button, restProps, /*#__PURE__*/React.createElement(UploadOutlined, null), " ", locale.clickToUpload);
    };

    _this.renderFile = function (item) {
      var getFieldDecorator = _this.props.form.getFieldDecorator;
      var required = item.required,
          id = item.id,
          _item$rules4 = item.rules,
          rules = _item$rules4 === void 0 ? [] : _item$rules4,
          _item$ctrlProps5 = item.ctrlProps,
          ctrlProps = _item$ctrlProps5 === void 0 ? {} : _item$ctrlProps5;
      var _ctrlProps$readOnly3 = ctrlProps.readOnly,
          readOnly = _ctrlProps$readOnly3 === void 0 ? false : _ctrlProps$readOnly3;
      var restProps = {};
      if (readOnly) restProps.disabled = true;

      var rulesDefault = _this.filterRules(rules);

      if (required) rulesDefault.unshift(COMMONDATE_RULE);

      var fileProps = _objectSpread(_objectSpread({}, _this.renderCommonAttrs(item)), restProps);

      return getFieldDecorator(id, {
        initialValue: _this.handleInit(item),
        rules: rulesDefault
      })( /*#__PURE__*/React.createElement(Upload, fileProps, /*#__PURE__*/React.createElement(LocaleReceiver, {
        componentName: "DynamicAttribute",
        defaultLocale: defaultLocale.DynamicAttribute
      }, function (locale) {
        return _this.getUploadBtn(item, restProps, locale);
      })));
    };

    _this.renderSlider = function (item) {
      var getFieldDecorator = _this.props.form.getFieldDecorator;
      var required = item.required,
          id = item.id,
          _item$rules5 = item.rules,
          rules = _item$rules5 === void 0 ? [] : _item$rules5,
          _item$ctrlProps6 = item.ctrlProps,
          ctrlProps = _item$ctrlProps6 === void 0 ? {} : _item$ctrlProps6,
          _item$data2 = item.data,
          data = _item$data2 === void 0 ? {} : _item$data2;
      var _ctrlProps$readOnly4 = ctrlProps.readOnly,
          readOnly = _ctrlProps$readOnly4 === void 0 ? false : _ctrlProps$readOnly4;
      var restProps = {};
      if (readOnly) restProps.disabled = true;

      var rulesDefault = _this.filterRules(rules);

      if (required) rulesDefault.unshift(COMMONDATE_RULE);

      var sliderProps = _objectSpread(_objectSpread(_objectSpread({}, _this.renderCommonAttrs(item)), restProps), {}, {
        marks: data
      });

      return getFieldDecorator(id, {
        initialValue: _this.handleInit(item) || 0,
        rules: rulesDefault
      })( /*#__PURE__*/React.createElement(Slider, sliderProps));
    };

    _this.renderRate = function (item) {
      var getFieldDecorator = _this.props.form.getFieldDecorator;
      var required = item.required,
          id = item.id,
          _item$rules6 = item.rules,
          rules = _item$rules6 === void 0 ? [] : _item$rules6,
          _item$ctrlProps7 = item.ctrlProps,
          ctrlProps = _item$ctrlProps7 === void 0 ? {} : _item$ctrlProps7,
          _item$data3 = item.data,
          data = _item$data3 === void 0 ? {} : _item$data3;
      var _ctrlProps$readOnly5 = ctrlProps.readOnly,
          readOnly = _ctrlProps$readOnly5 === void 0 ? false : _ctrlProps$readOnly5;
      var restProps = {};
      if (readOnly) restProps.disabled = true;

      var rulesDefault = _this.filterRules(rules);

      if (required) rulesDefault.unshift(COMMONDATE_RULE);

      var sliderProps = _objectSpread(_objectSpread(_objectSpread({}, _this.renderCommonAttrs(item)), restProps), {}, {
        marks: data
      });

      return getFieldDecorator(id, {
        initialValue: _this.handleInit(item),
        rules: rulesDefault
      })( /*#__PURE__*/React.createElement(Rate, _extends({
        className: "dynamic-rate"
      }, sliderProps)));
    };

    _this.renderCombination = function (item) {
      var getFieldDecorator = _this.props.form.getFieldDecorator;
      var required = item.required,
          id = item.id,
          prefixId = item.prefixId,
          suffixId = item.suffixId,
          _item$rules7 = item.rules,
          rules = _item$rules7 === void 0 ? [] : _item$rules7,
          _item$ctrlProps8 = item.ctrlProps,
          ctrlProps = _item$ctrlProps8 === void 0 ? {} : _item$ctrlProps8,
          _item$addonBefore = item.addonBefore,
          addonBefore = _item$addonBefore === void 0 ? ['Http://', 'Https://'] : _item$addonBefore,
          _item$addonAfter = item.addonAfter,
          addonAfter = _item$addonAfter === void 0 ? ['.com', '.jp', '.cn', '.org'] : _item$addonAfter;
      var _ctrlProps$readOnly6 = ctrlProps.readOnly,
          readOnly = _ctrlProps$readOnly6 === void 0 ? false : _ctrlProps$readOnly6;
      var restProps = {};
      if (readOnly) restProps.disabled = true;

      var rulesDefault = _this.filterRules(rules);

      if (required) rulesDefault.unshift(COMMONDATE_RULE);

      var urlProps = _objectSpread(_objectSpread(_objectSpread({}, _this.renderCommonAttrs(item)), restProps), {}, {
        allowClear: true,
        addonBefore: _this.generateSelectBefore(addonBefore, restProps, prefixId),
        addonAfter: _this.generateSelectAfter(addonAfter, restProps, suffixId)
      });

      return getFieldDecorator(id, {
        initialValue: _this.handleInit(item),
        rules: rulesDefault
      })( /*#__PURE__*/React.createElement(Input, urlProps));
    };

    _this.filterEmail = function (value) {
      var data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
      var emailSearchResult;

      if (!value || value.indexOf('@') >= 0) {
        emailSearchResult = [];
      } else {
        emailSearchResult = data.map(function (domain) {
          return "".concat(value, "@").concat(domain);
        });
      }

      _this.setState({
        emailSearchResult: emailSearchResult
      });
    };

    _this.renderEmailOption = function (item) {
      var _item$data4 = item.data,
          data = _item$data4 === void 0 ? [] : _item$data4,
          id = item.id;
      var getFieldValue = _this.props.form.getFieldValue;
      var target = getFieldValue(id);
      return _this.filterEmail(target, data);
    };

    _this.renderEmail = function (item) {
      var getFieldDecorator = _this.props.form.getFieldDecorator;
      var required = item.required,
          id = item.id,
          _item$rules8 = item.rules,
          rules = _item$rules8 === void 0 ? [] : _item$rules8,
          _item$ctrlProps9 = item.ctrlProps,
          ctrlProps = _item$ctrlProps9 === void 0 ? {} : _item$ctrlProps9;
      var _ctrlProps$readOnly7 = ctrlProps.readOnly,
          readOnly = _ctrlProps$readOnly7 === void 0 ? false : _ctrlProps$readOnly7;
      var _this$state$emailSear = _this.state.emailSearchResult,
          emailSearchResult = _this$state$emailSear === void 0 ? [] : _this$state$emailSear;
      var children = emailSearchResult.map(function (email) {
        return /*#__PURE__*/React.createElement(AutoComplete.Option, {
          key: email
        }, email);
      });
      var restProps = {};
      if (readOnly) restProps.disabled = true;

      var rulesDefault = _this.filterRules(rules);

      if (required) rulesDefault.unshift(COMMONDATE_RULE);

      var emailProps = _objectSpread(_objectSpread(_objectSpread({}, _this.renderCommonAttrs(item)), restProps), {}, {
        allowClear: true,
        style: {
          width: '100%'
        },
        onSearch: function onSearch() {
          return _this.renderEmailOption(item);
        }
      });

      return getFieldDecorator(id, {
        initialValue: _this.handleInit(item),
        rules: rulesDefault
      })( /*#__PURE__*/React.createElement(AutoComplete, emailProps, children));
    };

    _this.renderRadioGroup = function (item) {
      var getFieldDecorator = _this.props.form.getFieldDecorator;
      var required = item.required,
          id = item.id,
          _item$rules9 = item.rules,
          rules = _item$rules9 === void 0 ? [] : _item$rules9,
          _item$ctrlProps10 = item.ctrlProps,
          ctrlProps = _item$ctrlProps10 === void 0 ? {} : _item$ctrlProps10,
          _item$data5 = item.data,
          data = _item$data5 === void 0 ? [] : _item$data5,
          type = item.type;
      var _ctrlProps$readOnly8 = ctrlProps.readOnly,
          readOnly = _ctrlProps$readOnly8 === void 0 ? false : _ctrlProps$readOnly8;
      var restProps = {};
      if (readOnly) restProps.disabled = true;

      var rulesDefault = _this.filterRules(rules);

      if (required) rulesDefault.unshift(COMMONDATE_RULE);

      var radioProps = _objectSpread(_objectSpread({}, _this.renderCommonAttrs(item)), restProps);

      return getFieldDecorator(id, {
        initialValue: _this.handleInit(item),
        rules: rulesDefault
      })(_this.renderGroup(type, data, radioProps));
    };

    _this.renderGroup = function (type) {
      var data = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
      var props = arguments.length > 2 ? arguments[2] : undefined;

      if (type === 'radioGroup') {
        return /*#__PURE__*/React.createElement(Radio.Group, _extends({
          className: "dynamic-radio-group"
        }, props), data.length !== 0 && data.map(function (radio, index) {
          return /*#__PURE__*/React.createElement(Radio, {
            value: radio.value,
            key: "radio-group-".concat(index)
          }, radio.label);
        }));
      } else {
        return /*#__PURE__*/React.createElement(Radio.Group, _extends({
          className: "dynamic-radio-group"
        }, props), data.length !== 0 && data.map(function (radio, index) {
          return /*#__PURE__*/React.createElement(Radio.Button, {
            value: radio.value,
            key: "radio-button-".concat(index)
          }, radio.label);
        }));
      }
    };

    _this.renderCheckbox = function (item) {
      var getFieldDecorator = _this.props.form.getFieldDecorator;
      var required = item.required,
          id = item.id,
          _item$rules10 = item.rules,
          rules = _item$rules10 === void 0 ? [] : _item$rules10,
          _item$ctrlProps11 = item.ctrlProps,
          ctrlProps = _item$ctrlProps11 === void 0 ? {} : _item$ctrlProps11,
          _item$data6 = item.data,
          data = _item$data6 === void 0 ? [] : _item$data6;
      var _ctrlProps$readOnly9 = ctrlProps.readOnly,
          readOnly = _ctrlProps$readOnly9 === void 0 ? false : _ctrlProps$readOnly9;
      var restProps = {};
      if (readOnly) restProps.disabled = true;

      var rulesDefault = _this.filterRules(rules);

      if (required) rulesDefault.unshift(COMMONDATE_RULE);

      var checkboxProps = _objectSpread(_objectSpread({
        options: data
      }, _this.renderCommonAttrs(item)), restProps);

      return getFieldDecorator(id, {
        initialValue: _this.handleInit(item),
        rules: rulesDefault
      })( /*#__PURE__*/React.createElement(Checkbox.Group, _extends({
        className: "dynamic-checkbox-group"
      }, checkboxProps)));
    };

    _this.renderDateItem = function (props, type) {
      switch (type) {
        case 'datetimepicker':
          return /*#__PURE__*/React.createElement(DatePicker, props);

        case 'dateRangePicker':
          return /*#__PURE__*/React.createElement(DatePicker.RangePicker, _extends({
            className: "dynamic-range-picker"
          }, props));

        default:
          break;
      }
    };

    _this.renderDatePicker = function (item) {
      var _this$props3 = _this.props,
          getFieldDecorator = _this$props3.form.getFieldDecorator,
          initValues = _this$props3.initValues;
      var required = item.required,
          id = item.id,
          format = item.format,
          type = item.type,
          _item$ctrlProps12 = item.ctrlProps,
          ctrlProps = _item$ctrlProps12 === void 0 ? {} : _item$ctrlProps12,
          _item$rules11 = item.rules,
          rules = _item$rules11 === void 0 ? [] : _item$rules11;
      var _ctrlProps$readOnly10 = ctrlProps.readOnly,
          readOnly = _ctrlProps$readOnly10 === void 0 ? false : _ctrlProps$readOnly10;
      var restProps = {};
      if (readOnly) restProps.disabled = true;
      var fdxFormat = format;

      if (format) {
        fdxFormat = transFishformToFdx(format, initValues, id);
      }

      var rulesDefault = _this.filterRules(rules);

      if (required) rulesDefault.unshift(COMMONDATE_RULE);

      var dateProps = _objectSpread(_objectSpread({
        style: {
          width: '100%'
        },
        format: fdxFormat,
        allowClear: true,
        showTime: judgeShowTime(initValues, id)
      }, _this.renderCommonAttrs(item)), restProps);

      var initTime = type !== 'dateRangePicker' ? _this.handleInit(item) : _this.formatRangeTime(_this.handleInit(item), fdxFormat);
      return getFieldDecorator(id, {
        initialValue: initTime,
        rules: rulesDefault
      })(_this.renderDateItem(dateProps, type));
    };

    _this.formatRangeTime = function (value, format) {
      if (value === null) return null;
      return value.map(function (time) {
        return moment(time, format);
      });
    };

    _this.renderTimePicker = function (item) {
      var getFieldDecorator = _this.props.form.getFieldDecorator;
      var required = item.required,
          id = item.id,
          _item$format = item.format,
          format = _item$format === void 0 ? 'HH:mm:ss' : _item$format,
          _item$ctrlProps13 = item.ctrlProps,
          ctrlProps = _item$ctrlProps13 === void 0 ? {} : _item$ctrlProps13,
          _item$rules12 = item.rules,
          rules = _item$rules12 === void 0 ? [] : _item$rules12;
      var _ctrlProps$readOnly11 = ctrlProps.readOnly,
          readOnly = _ctrlProps$readOnly11 === void 0 ? false : _ctrlProps$readOnly11;
      var restProps = {};
      if (readOnly) restProps.disabled = true;

      var rulesDefault = _this.filterRules(rules);

      if (required) rulesDefault.unshift(COMMONDATE_RULE);

      var timeProps = _objectSpread(_objectSpread({
        style: {
          width: '100%'
        },
        format: format,
        allowClear: true
      }, _this.renderCommonAttrs(item)), restProps);

      var initTime = _this.handleInit(item) ? moment(_this.handleInit(item), format) : null;
      return getFieldDecorator(id, {
        initialValue: initTime,
        rules: rulesDefault
      })( /*#__PURE__*/React.createElement(TimePicker, timeProps));
    };

    _this.renderSelect = function (item) {
      var getFieldDecorator = _this.props.form.getFieldDecorator;
      var required = item.required,
          id = item.id,
          type = item.type,
          _item$rules13 = item.rules,
          rules = _item$rules13 === void 0 ? [] : _item$rules13,
          _item$ctrlProps14 = item.ctrlProps,
          ctrlProps = _item$ctrlProps14 === void 0 ? {} : _item$ctrlProps14;
      var _ctrlProps$readOnly12 = ctrlProps.readOnly,
          readOnly = _ctrlProps$readOnly12 === void 0 ? false : _ctrlProps$readOnly12;
      var restProps = {};
      if (readOnly) restProps.disabled = true;

      var rulesDefault = _this.filterRules(rules);

      if (required) rulesDefault.unshift(type === "multiselect" ? COMMONARRAY_RULE : COMMONRule);

      var selectProps = _objectSpread(_objectSpread({
        allowClear: true,
        width: '100%'
      }, _this.renderCommonAttrs(item)), restProps);

      if (type === "multiselect") selectProps.mode = "multiple";
      return getFieldDecorator(id, {
        initialValue: _this.handleInit(item),
        rules: rulesDefault
      })( /*#__PURE__*/React.createElement(Select, _extends({
        className: "dynamic-select"
      }, selectProps), _this.renderOptions(item)));
    };

    _this.renderTreeSelect = function (item) {
      var getFieldDecorator = _this.props.form.getFieldDecorator;
      var required = item.required,
          id = item.id,
          _item$rules14 = item.rules,
          rules = _item$rules14 === void 0 ? [] : _item$rules14,
          _item$ctrlProps15 = item.ctrlProps,
          ctrlProps = _item$ctrlProps15 === void 0 ? {} : _item$ctrlProps15;
      var _ctrlProps$readOnly13 = ctrlProps.readOnly,
          readOnly = _ctrlProps$readOnly13 === void 0 ? false : _ctrlProps$readOnly13;
      var restProps = {};
      if (readOnly) restProps.disabled = true;

      var rulesDefault = _this.filterRules(rules);

      if (required) rulesDefault.unshift(COMMONDATE_RULE);

      var selectTreeProps = _objectSpread(_objectSpread({
        width: '100%',
        allowClear: true,
        dropdownStyle: {
          maxHeight: 400,
          overflow: 'auto'
        },
        treeDefaultExpandAll: true
      }, _this.renderCommonAttrs(item)), restProps);

      return getFieldDecorator(id, {
        initialValue: _this.handleInit(item),
        rules: rulesDefault
      })( /*#__PURE__*/React.createElement(TreeSelect, _extends({
        className: "dynamic-select"
      }, selectTreeProps)));
    };

    _this.renderCascader = function (item) {
      var getFieldDecorator = _this.props.form.getFieldDecorator;
      var required = item.required,
          id = item.id,
          _item$rules15 = item.rules,
          rules = _item$rules15 === void 0 ? [] : _item$rules15,
          _item$ctrlProps16 = item.ctrlProps,
          ctrlProps = _item$ctrlProps16 === void 0 ? {} : _item$ctrlProps16;
      var _ctrlProps$readOnly14 = ctrlProps.readOnly,
          readOnly = _ctrlProps$readOnly14 === void 0 ? false : _ctrlProps$readOnly14;
      var restProps = {};
      if (readOnly) restProps.disabled = true;

      var rulesDefault = _this.filterRules(rules);

      if (required) rulesDefault.unshift(COMMONDATE_RULE);

      var cascaderProps = _objectSpread(_objectSpread({
        width: '100%',
        allowClear: true
      }, _this.renderCommonAttrs(item)), restProps);

      return getFieldDecorator(id, {
        initialValue: _this.handleInit(item),
        rules: rulesDefault
      })( /*#__PURE__*/React.createElement(Cascader, _extends({
        className: "dynamic-cascader"
      }, cascaderProps)));
    };

    _this.renderPopEdit = function (item) {
      var getFieldDecorator = _this.props.form.getFieldDecorator;
      var required = item.required,
          id = item.id,
          _item$popeditProps = item.popeditProps,
          popeditProps = _item$popeditProps === void 0 ? {} : _item$popeditProps,
          _item$rules16 = item.rules,
          rules = _item$rules16 === void 0 ? [] : _item$rules16,
          _item$ctrlProps17 = item.ctrlProps,
          ctrlProps = _item$ctrlProps17 === void 0 ? {} : _item$ctrlProps17;
      var _ctrlProps$readOnly15 = ctrlProps.readOnly,
          readOnly = _ctrlProps$readOnly15 === void 0 ? false : _ctrlProps$readOnly15;

      var rulesDefault = _this.filterRules(rules);

      if (required) rulesDefault.unshift(COMMONDATE_RULE);
      var restProps = {};
      if (readOnly) restProps.disabled = true;
      popeditProps.inputProps = _objectSpread(_objectSpread({
        width: '100%'
      }, ctrlProps), popeditProps.inputProps);
      popeditProps.modalProps = _objectSpread(_objectSpread({}, _this.renderCommonAttrs(item)), popeditProps.modalProps);

      var defaultProps = _objectSpread(_objectSpread({}, restProps), popeditProps);

      var defaultValue = _this.handleInit(item);

      if (typeof defaultValue === 'string') {
        try {
          defaultValue = JSON.parse(defaultValue);
        } catch (error) {// console.log('popEdit 数据格式错误：', error)
        }
      }

      return getFieldDecorator(id, {
        initialValue: defaultValue,
        rules: rulesDefault
      })( /*#__PURE__*/React.createElement(PopEdit, defaultProps));
    };

    _this.handleProps = function (formProps) {
      // eslint-disable-next-line no-unused-vars
      var _formProps$colLayout2 = formProps.colLayout,
          colLayout = _formProps$colLayout2 === void 0 ? ColLayout : _formProps$colLayout2,
          _formProps$formItemLa2 = formProps.formItemLayout,
          formItemLayout = _formProps$formItemLa2 === void 0 ? FormItemLayout : _formProps$formItemLa2,
          resetProps = _objectWithoutProperties(formProps, _excluded);

      return _objectSpread(_objectSpread(_objectSpread({}, colLayout), formItemLayout), resetProps);
    };

    _this.state = {
      emailSearchResult: [],
      popEditModalVisible: false,
      registry: _objectSpread({
        text: _this.renderInput,
        textarea: _this.renderInput,
        password: _this.renderInput,
        hidden: _this.renderInput,
        datetimepicker: _this.renderDatePicker,
        dateRangePicker: _this.renderDatePicker,
        combobox: _this.renderSelect,
        multiselect: _this.renderSelect,
        number: _this.renderNumber,
        popedit: _this.renderPopEdit,
        treeSelect: _this.renderTreeSelect,
        cascader: _this.renderCascader,
        file: _this.renderFile,
        radioGroup: _this.renderRadioGroup,
        radioButton: _this.renderRadioGroup,
        checkbox: _this.renderCheckbox,
        timePicker: _this.renderTimePicker,
        combination: _this.renderCombination,
        email: _this.renderEmail,
        slider: _this.renderSlider,
        rate: _this.renderRate,
        submit: _this.renderSubmit
      }, _this.appendAddition())
    };
    return _this;
  }

  _createClass(DynamicAttribute, [{
    key: "render",
    value: function render() {
      var _this$props4 = this.props,
          layout = _this$props4.layout,
          formProps = _this$props4.formProps,
          children = _this$props4.children;
      return /*#__PURE__*/React.createElement("div", {
        className: "fdx-form"
      }, /*#__PURE__*/React.createElement(Form, _extends({}, this.handleProps(formProps), {
        onSubmit: this.getFieldsValue
      }), /*#__PURE__*/React.createElement(Row, null, layout.map(this.renderItem), children)));
    }
  }]);

  return DynamicAttribute;
}(Component);

DynamicAttribute.propTypes = {
  formProps: PropTypes.object,
  layout: PropTypes.array,
  initValues: PropTypes.array
};
DynamicAttribute.defaultProps = {
  formProps: {
    colLayout: ColLayout,
    formItemLayout: FormItemLayout
  },
  layout: [],
  initValues: [],
  additionRegistry: []
};
export default Form.create()(DynamicAttribute);