"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _react = _interopRequireWildcard(require("react"));
var _antd = require("antd");
var _data = require("../data");
var _RenderItemGroup = _interopRequireDefault(require("../FormComp/RenderItemGroup"));
var _utils = require("../utils");
var _IconNode = _interopRequireDefault(require("../components/IconNode"));
var _TabForm = _interopRequireDefault(require("../StandardForm/TabForm"));
var _StepForm = _interopRequireDefault(require("../StandardForm/StepForm"));
var _ActionList = _interopRequireDefault(require("../StandardForm/ActionList"));
var _StandardDragModal = require("../StandardDragModal");
var _index = _interopRequireDefault(require("./style/index"));
var _classnames = _interopRequireDefault(require("classnames"));
var _ConfigContext = require("../ConfigContext");
require("./style/index.less");
var _useLanguage = require("../hooks/use-language");
var _lodash = require("lodash");
var _excluded = ["children", "className", "style", "size", "type", "formItemGroup", "title", "visible", "open", "formPrefix", "formPostfix", "initialValues", "parseTransform", "dateFormatter", "hideRequiredMark", "bodyStyle", "footer", "footerButtonGroup", "hideFooter", "getFormFields", "fieldStatus", "formLayout", "tabsConfig", "stepsConfig", "displayLayout", "dragAble", "itemGroupConfig", "getBodyMaxHeight"],
  _excluded2 = ["name", "type", "icon", "ghost", "disabled", "loading", "fn", "isHide"];
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
function _extends() { _extends = Object.assign ? Object.assign.bind() : 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 _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
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(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } // import { DraggableModal, DraggableModalProvider } from 'ant-design-draggable-modal'
// import 'ant-design-draggable-modal/dist/index.css'
// import { useThrottle } from "../hooks/use-throttle";
var StandardModal = function StandardModal(props) {
  var componentName = 'spec-standard-modal';
  var _useStyle = (0, _index.default)(componentName),
    _useStyle2 = _slicedToArray(_useStyle, 2),
    wrapSSR = _useStyle2[0],
    hashId = _useStyle2[1];
  var lang = (0, _useLanguage.useLanguageObject)(); // 当前使用的语言包
  var InitFanContext = (0, _react.useContext)(_ConfigContext.FanContext);
  var providerConfig = InitFanContext['StandardModal'] || {}; // 使用上下文（全局配置）设置扩展的配置项
  var ConcatModalProps = _objectSpread(_objectSpread({}, providerConfig), props);
  var children = ConcatModalProps.children,
    className = ConcatModalProps.className,
    style = ConcatModalProps.style,
    _ConcatModalProps$siz = ConcatModalProps.size,
    size = _ConcatModalProps$siz === void 0 ? 'md' : _ConcatModalProps$siz,
    type = ConcatModalProps.type,
    formItemGroup = ConcatModalProps.formItemGroup,
    title = ConcatModalProps.title,
    visible = ConcatModalProps.visible,
    open = ConcatModalProps.open,
    formPrefix = ConcatModalProps.formPrefix,
    formPostfix = ConcatModalProps.formPostfix,
    initialValues = ConcatModalProps.initialValues,
    parseTransform = ConcatModalProps.parseTransform,
    dateFormatter = ConcatModalProps.dateFormatter,
    hideRequiredMark = ConcatModalProps.hideRequiredMark,
    bodyStyle = ConcatModalProps.bodyStyle,
    footer = ConcatModalProps.footer,
    footerButtonGroup = ConcatModalProps.footerButtonGroup,
    hideFooter = ConcatModalProps.hideFooter,
    _getFormFields = ConcatModalProps.getFormFields,
    _ConcatModalProps$fie = ConcatModalProps.fieldStatus,
    fieldStatus = _ConcatModalProps$fie === void 0 ? 'default' : _ConcatModalProps$fie,
    _ConcatModalProps$for = ConcatModalProps.formLayout,
    formLayout = _ConcatModalProps$for === void 0 ? 'horizontal' : _ConcatModalProps$for,
    tabsConfig = ConcatModalProps.tabsConfig,
    stepsConfig = ConcatModalProps.stepsConfig,
    displayLayout = ConcatModalProps.displayLayout,
    _ConcatModalProps$dra = ConcatModalProps.dragAble,
    dragAble = _ConcatModalProps$dra === void 0 ? false : _ConcatModalProps$dra,
    _ConcatModalProps$ite = ConcatModalProps.itemGroupConfig,
    itemGroupConfig = _ConcatModalProps$ite === void 0 ? {} : _ConcatModalProps$ite,
    getBodyMaxHeight = ConcatModalProps.getBodyMaxHeight,
    otherProps = _objectWithoutProperties(ConcatModalProps, _excluded);
  var _Form$useForm = _antd.Form.useForm(),
    _Form$useForm2 = _slicedToArray(_Form$useForm, 1),
    modalForm = _Form$useForm2[0];

  // 通过useState控制按钮的禁用状态，结合setTimeout实现冷却时间（用于限制提交时不会重复点击）
  var _useState = (0, _react.useState)(false),
    _useState2 = _slicedToArray(_useState, 2),
    submitIsDisabled = _useState2[0],
    setSubmitIsDisabled = _useState2[1];
  var timerRef = (0, _react.useRef)(null);
  // const cooldownRef = useRef(false); // 使用 useRef 标记冷却状态，用于限制提交时不会重复点击(此方案无效）
  // const [modalFormRef, setModalFormRef] = useState<any>();  // <---- set the ref when Form Rendered(使用此方法会出现溢出事件）
  var _useState3 = (0, _react.useState)(0),
    _useState4 = _slicedToArray(_useState3, 2),
    bodyMaxHeight = _useState4[0],
    setBodyMaxHeight = _useState4[1];

  // setTabFormChild
  var _useState5 = (0, _react.useState)(),
    _useState6 = _slicedToArray(_useState5, 2),
    formChild = _useState6[0],
    setFormChild = _useState6[1]; // <---- set the ref when Form Rendered

  // 按钮栏是否有显示（默认显示）
  var hasFooterBar = (0, _react.useMemo)(function () {
    var openLog = false;
    if (type === 'tabForm' || type === 'stepForm') {
      if (type === 'tabForm') {
        var _activeTabInfo$action, _activeTabInfo$action2;
        var activeTabInfo = (formItemGroup || []).find(function (fItem) {
          return fItem.key === (tabsConfig === null || tabsConfig === void 0 ? void 0 : tabsConfig.activeKey);
        });
        openLog && console.log('rule 0-1', (activeTabInfo === null || activeTabInfo === void 0 || (_activeTabInfo$action = activeTabInfo.actions) === null || _activeTabInfo$action === void 0 ? void 0 : _activeTabInfo$action.length) > 0);
        return (activeTabInfo === null || activeTabInfo === void 0 || (_activeTabInfo$action2 = activeTabInfo.actions) === null || _activeTabInfo$action2 === void 0 ? void 0 : _activeTabInfo$action2.length) > 0;
      }
      if (type === 'stepForm') {
        var _currentStepInfo$acti, _currentStepInfo$acti2;
        var currentStepInfo = (formItemGroup || []).filter(function (fItem) {
          return !fItem.hideStep;
        })[stepsConfig.current];
        openLog && console.log('rule 0-2', (currentStepInfo === null || currentStepInfo === void 0 || (_currentStepInfo$acti = currentStepInfo.actions) === null || _currentStepInfo$acti === void 0 ? void 0 : _currentStepInfo$acti.length) > 0);
        return (currentStepInfo === null || currentStepInfo === void 0 || (_currentStepInfo$acti2 = currentStepInfo.actions) === null || _currentStepInfo$acti2 === void 0 ? void 0 : _currentStepInfo$acti2.length) > 0;
      }
      return true;
    } else {
      if (hideFooter) {
        openLog && console.log('rule 1');
        return false;
      }
      if (fieldStatus && fieldStatus !== 'default') {
        if (ConcatModalProps.hasOwnProperty('footerButtonGroup')) {
          // 如果有配置按钮组件，则还是要显示按钮
          return true;
        }
        openLog && console.log('rule 2');
        // disabled/viewOnly都不显示按钮
        return false;
      }
      if (ConcatModalProps.hasOwnProperty('footerButtonGroup') && footerButtonGroup) {
        var _footerButtonGroup;
        if (Array.isArray(footerButtonGroup) && footerButtonGroup.length === 0) {
          openLog && console.log('rule 4');
          // 返回为空数组不占用按钮栏
          return false;
        } else if (typeof footerButtonGroup === 'function' && (!footerButtonGroup() || ((_footerButtonGroup = footerButtonGroup()) === null || _footerButtonGroup === void 0 ? void 0 : _footerButtonGroup.length) === 0)) {
          openLog && console.log('rule 5');
          // 配置类型为Function且返回值为null或者返回数组长度为0时，不显示按钮栏
          return false;
        }
        openLog && console.log('rule 3');
        return true;
      } else if (footerButtonGroup === false) {
        openLog && console.log('rule 7');
        // 显示
        return true;
      }
      if (ConcatModalProps.hasOwnProperty('footer') && !footer) {
        openLog && console.log('rule 8');
        return false;
      }
      openLog && console.log('rule 9');
      return true;
    }
  }, [fieldStatus, hideFooter, footer, footerButtonGroup, type, tabsConfig, stepsConfig, formItemGroup]);
  // 设置限制弹窗高度
  var initBodyMaxHeight = function initBodyMaxHeight() {
    var title = ConcatModalProps.title;
    // 最大高度基础值调整成页面视口高度
    var bodyHeight = document.documentElement.clientHeight; // document.body.offsetHeight
    var baseReduce = 80 + 32 + 16; // 默认需要减去的高度（上下空白间距150及内部内容间距16*2
    // console.log('弹窗是否有按钮：', hasFooterBar ? '是' : '否')
    setBodyMaxHeight(bodyHeight - (title ? 55 : 0) - (hasFooterBar ? 55 : 0) - baseReduce);
    // setBodyMaxHeight(`${bodyHeight - (title ? 55 : 0) - ((footer || footerButtonGroup) ? 55 : 0) - baseReduce +
    // ((fieldStatus && fieldStatus !== 'default' && !footerButtonGroup) || hideFooter ? 55 : 0)}px`)
  };
  // fill Form when modal open 此处可解决获取  Form.useForm  warning
  (0, _react.useEffect)(function () {
    if (visible && modalForm) {
      // <---- check ref before use the form instance
      if (initialValues && _typeof(initialValues) === 'object') {
        initialValues && modalForm.setFieldsValue(parseTransform ? parseTransform(_objectSpread({}, initialValues)) : _objectSpread({}, initialValues));
        forceUpdateForm();
      }
    }
    // if (!visible && modalFormRef) {
    //   clearAllFieldsValue() // 清空表单传参数
    // }
  }, [modalForm, visible]);
  (0, _react.useEffect)(function () {
    if (visible) getBodyMaxHeight === null || getBodyMaxHeight === void 0 || getBodyMaxHeight(bodyMaxHeight);
    return function () {
      if (!visible) getBodyMaxHeight === null || getBodyMaxHeight === void 0 || getBodyMaxHeight(0);
    };
  }, [visible, bodyMaxHeight]);
  (0, _react.useEffect)(function () {
    if (visible) {
      initBodyMaxHeight();
      // 让resize事件触发 initBodyMaxHeight
      window.addEventListener('resize', initBodyMaxHeight);
    } else {
      window.removeEventListener('resize', initBodyMaxHeight);
    }
  }, [fieldStatus, title, visible, hideFooter, footer, footerButtonGroup]);
  var handleSubmit = (0, _lodash.debounce)(function () {
    if (!submitIsDisabled) {
      setSubmitIsDisabled(true);
      // cooldownRef.current = true;
      var _type = ConcatModalProps.type,
        _formItemGroup = ConcatModalProps.formItemGroup,
        onSubmit = ConcatModalProps.onSubmit,
        confirmLoading = ConcatModalProps.confirmLoading;
      if (_type === 'form' || _type === 'gridForm') {
        modalForm.validateFields().then(function (values) {
          if (Object.prototype.hasOwnProperty.call(values, 'false')) {
            delete values.false; // 自定义结构会莫名的出来一个false字段
          }
          var resultValues = (0, _utils.UtilValueFormat)(values, _formItemGroup, dateFormatter);
          if (onSubmit) {
            onSubmit(_objectSpread({}, resultValues));
          }
        }).catch(function () {
          // 定位到第一条表单异常的
          var errorCollection = Array.prototype.slice.call(document.getElementsByClassName('ant-form-item-has-error'));
          if (errorCollection[0] && errorCollection[0].getElementsByTagName('input')) {
            Array.prototype.slice.call(errorCollection[0].getElementsByTagName('input'))[0].focus();
          }
          // console.error('表单填写有误', errorInfo, '第一条数据',errorInfo.errorFields[0].name[0])
        });
      } else if (_type === 'stepForm' || _type === 'tabForm') {
        // onSubmit && onSubmit()
        formChild.validateFields().then(function (values) {
          // console.log(values)
          if (Object.prototype.hasOwnProperty.call(values, 'false')) {
            delete values.false; // 自定义结构会莫名的出来一个false字段
          }
          var resultValues = (0, _utils.UtilValueFormat)(values, _formItemGroup, dateFormatter);
          if (onSubmit) {
            onSubmit(_objectSpread({}, resultValues));
          }
        }).catch(function () {
          // 定位到第一条表单异常的
          var errorCollection = Array.prototype.slice.call(document.getElementsByClassName('ant-form-item-has-error'));
          if (errorCollection[0] && errorCollection[0].getElementsByTagName('input')) {
            Array.prototype.slice.call(errorCollection[0].getElementsByTagName('input'))[0].focus();
          }
          // console.error('表单填写有误', errorInfo, '第一条数据',errorInfo.errorFields[0].name[0])
        });
      } else {
        // 没有表单数组 formItemGroup 配置
        onSubmit && onSubmit();
      }

      // @ts-ignore 设置1秒后解除禁用
      timerRef.current = setTimeout(function () {
        setSubmitIsDisabled(false);
      }, 1000);
    }
  }, 100);
  (0, _react.useEffect)(function () {
    return function () {
      if (timerRef.current) clearTimeout(timerRef.current);
    };
  }, []);
  // 重置所有表单
  var clearAllFieldsValue = function clearAllFieldsValue() {
    // let allFields = {}
    // Object.keys(modalForm.getFieldsValue()).map((item) => allFields[item] = undefined)
    // modalForm.setFieldsValue(allFields) // 直接清空表单的赋值(initialValues传值如果没有前后赋值没有全部带上所有字段，则会默认又使用之前的部分未传参字段)
    modalForm.resetFields(); // 直接使用这个无效
  };
  var onAfterClose = function onAfterClose() {
    var afterClose = ConcatModalProps.afterClose;
    if (type === 'form') clearAllFieldsValue();
    if (afterClose) afterClose();
  };
  var handleCancel = function handleCancel() {
    var onCancel = ConcatModalProps.onCancel;
    if (onCancel) onCancel();
  };

  // 强制更新表单值，用于赋初始化实例值
  var forceUpdateForm = function forceUpdateForm() {
    _getFormFields && _getFormFields(modalForm.getFieldsValue() || {}, modalForm);
  };
  var renderFormItemGroup = function renderFormItemGroup() {
    var fieldStatus = ConcatModalProps.fieldStatus,
      formItemGroup = ConcatModalProps.formItemGroup,
      _ConcatModalProps$siz2 = ConcatModalProps.size,
      size = _ConcatModalProps$siz2 === void 0 ? 'md' : _ConcatModalProps$siz2,
      type = ConcatModalProps.type;
    if (Array.isArray(formItemGroup)) {
      if (type === 'gridForm') {
        // 栅格组
        return /*#__PURE__*/_react.default.createElement(_antd.Row, {
          gutter: 20
        }, (formItemGroup || []).map(function (item, index) {
          var childrenFields = item.fields || [];
          if (item.label) {
            childrenFields = [{
              type: item.type,
              label: item.label,
              protoConfig: _objectSpread({}, item.protoConfig)
              // protoConfig: { className: '', ...item.protoConfig }
            }].concat(childrenFields);
          }
          return /*#__PURE__*/_react.default.createElement(_antd.Col, {
            key: index,
            span: item.gridSpan || 24
          }, /*#__PURE__*/_react.default.createElement(_RenderItemGroup.default, _extends({
            size: size,
            layout: formLayout,
            doUpdateFormFields: function doUpdateFormFields() {
              return forceUpdateForm();
            },
            displayLayout: item.displayLayout || displayLayout,
            itemGroup: childrenFields,
            fieldStatus: fieldStatus,
            form: modalForm
          }, itemGroupConfig)));
        }));
      }
      return /*#__PURE__*/_react.default.createElement(_RenderItemGroup.default, _extends({
        size: size,
        layout: formLayout,
        doUpdateFormFields: function doUpdateFormFields() {
          return forceUpdateForm();
        },
        displayLayout: displayLayout,
        itemGroup: formItemGroup,
        fieldStatus: fieldStatus,
        form: modalForm
      }, itemGroupConfig));
    }
    return formItemGroup;
  };
  var handleStepType = function handleStepType(type, extraFunc) {
    var current = stepsConfig.current;
    switch (type) {
      case 'submit':
      case 'next':
        // 获取当前步骤的表单配置下有 rules 的控件进行校验（自定义的控件则自己有业务层面处理添加校验）
        // console.log('执行下一步骤，需要优先进行校验')
        var currentFields = (formItemGroup || [])[current].fields;
        var validatorGroup = currentFields && Array.isArray(currentFields) ? currentFields.map(function (fItem) {
          return fItem.rules ? fItem.filedName || fItem.filedName : null;
        }) : [];
        formChild.validateFields(validatorGroup).then(function () {
          // if (stepClick) stepClick(type, formChild, values);
          extraFunc && extraFunc();
        }).catch(function () {
          // console.log('表单校验不通过 ', errorFields.map(err => err))
        });
        break;
      case 'prev':
        // if (stepClick) stepClick(type, formChild);
        extraFunc && extraFunc();
        break;
      case 'cancel':
        // if (stepClick) stepClick(type, formChild);
        extraFunc && extraFunc();
        break;
      default:
        // extraFunc()
        break;
    }
  };
  var renderButtonGroup = function renderButtonGroup() {
    var footerButtonGroup = ConcatModalProps.footerButtonGroup,
      confirmLoading = ConcatModalProps.confirmLoading,
      cancelText = ConcatModalProps.cancelText,
      confirmText = ConcatModalProps.confirmText,
      okText = ConcatModalProps.okText,
      okButtonProps = ConcatModalProps.okButtonProps,
      confirmButtonProps = ConcatModalProps.confirmButtonProps,
      cancelButtonProps = ConcatModalProps.cancelButtonProps;
    if (footerButtonGroup) {
      if (Array.isArray(footerButtonGroup)) {
        if (footerButtonGroup.length === 0) return null; // <div>按钮组合配置为空</div>
        return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, footerButtonGroup.map(function (item) {
          if (_typeof(item) === 'object' && !(item !== null && item !== void 0 && item.$$typeof)) {
            if (item.isHide) return null;
            var name = item.name,
              _type2 = item.type,
              icon = item.icon,
              ghost = item.ghost,
              disabled = item.disabled,
              loading = item.loading,
              fn = item.fn,
              isHide = item.isHide,
              others = _objectWithoutProperties(item, _excluded2);
            return /*#__PURE__*/_react.default.createElement(_antd.Button, _extends({
              key: name,
              type: _type2 || 'primary',
              icon: icon ? /*#__PURE__*/_react.default.createElement(_IconNode.default, {
                icon: icon
              }) : null,
              ghost: ghost,
              disabled: disabled,
              loading: loading,
              onClick: fn ? function (e) {
                return fn(item, modalForm, ConcatModalProps, e);
              } : null
            }, others), name);
          } else {
            return item; // 如果是DOM，则直接渲染
          }
        }));
      }
      if (typeof footerButtonGroup === 'function') {
        return footerButtonGroup(modalForm, ConcatModalProps);
      }
      return footerButtonGroup;
    }
    if (footer) return footer;
    return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_antd.Button, _extends({
      key: "submit",
      type: 'primary',
      disabled: submitIsDisabled,
      loading: confirmLoading,
      onClick: handleSubmit
    }, confirmButtonProps, okButtonProps), confirmText || okText || (lang === null || lang === void 0 ? void 0 : lang['global.confirm.text']) || '确定'), /*#__PURE__*/_react.default.createElement(_antd.Button, _extends({
      key: "back",
      onClick: handleCancel
    }, cancelButtonProps), cancelText || (lang === null || lang === void 0 ? void 0 : lang['global.cancel.text']) || '取消'));
  };
  var renderFooter = function renderFooter() {
    if (type === 'stepForm') {
      var _currentStepInfo$acti3;
      // 过滤隐藏掉的步骤表单
      var currentStepInfo = (formItemGroup || []).filter(function (fItem) {
        return !fItem.hideStep;
      })[stepsConfig.current];
      return (currentStepInfo === null || currentStepInfo === void 0 || (_currentStepInfo$acti3 = currentStepInfo.actions) === null || _currentStepInfo$acti3 === void 0 ? void 0 : _currentStepInfo$acti3.length) > 0 ? /*#__PURE__*/_react.default.createElement(_ActionList.default, {
        list: currentStepInfo.actions || [],
        onStep: handleStepType,
        form: formChild,
        other: ConcatModalProps
      }) : null;
    }
    if (type === 'tabForm') {
      var _activeTabInfo$action3;
      var activeTabInfo = (formItemGroup || []).find(function (fItem) {
        return fItem.key === (tabsConfig === null || tabsConfig === void 0 ? void 0 : tabsConfig.activeKey);
      });
      return (activeTabInfo === null || activeTabInfo === void 0 || (_activeTabInfo$action3 = activeTabInfo.actions) === null || _activeTabInfo$action3 === void 0 ? void 0 : _activeTabInfo$action3.length) > 0 ? /*#__PURE__*/_react.default.createElement(_ActionList.default, {
        list: (activeTabInfo === null || activeTabInfo === void 0 ? void 0 : activeTabInfo.actions) || [],
        form: formChild,
        other: ConcatModalProps
      }) : null;
    }
    return hasFooterBar ? renderButtonGroup() : null;
  };
  // 内容渲染
  var renderChildrenNodes = function renderChildrenNodes() {
    return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, children, (type === 'form' || type === 'gridForm') && /*#__PURE__*/_react.default.createElement(_antd.Form, {
      layout: formLayout
      // ref={(formInstance)=> {
      //   // console.log('formInstance', formInstance)
      //   // setModalFormRef(formInstance)
      // }}
      ,
      form: modalForm,
      onFinish: handleSubmit,
      hideRequiredMark: fieldStatus === 'viewOnly' || hideRequiredMark
      // initialValues={{ ...initialValues }}
      ,
      scrollToFirstError: true,
      className: "modalForm"
    }, formPrefix && /*#__PURE__*/_react.default.createElement(_antd.Row, null, formPrefix(modalForm, ConcatModalProps, forceUpdateForm)), formItemGroup ? renderFormItemGroup() : null, formPostfix && /*#__PURE__*/_react.default.createElement(_antd.Row, null, formPostfix(modalForm, ConcatModalProps, forceUpdateForm), " ")), type === 'tabForm' && /*#__PURE__*/_react.default.createElement(_TabForm.default, {
      grid: size,
      layout: formLayout,
      fieldStatus: fieldStatus,
      actionHide: true
      // @ts-ignore
      ,
      getFormFields: function getFormFields(fields, form) {
        setFormChild(form);
        _getFormFields && _getFormFields(fields, form);
      },
      formItemGroup: formItemGroup,
      tabsConfig: tabsConfig,
      onSubmit: handleSubmit,
      initialValues: _objectSpread({}, initialValues),
      parseTransform: parseTransform,
      displayLayout: displayLayout
    }), type === 'stepForm' && /*#__PURE__*/_react.default.createElement(_StepForm.default, {
      grid: size,
      layout: formLayout,
      fieldStatus: fieldStatus,
      actionHide: true
      // @ts-ignore
      ,
      getFormFields: function getFormFields(fields, form) {
        setFormChild(form);
        _getFormFields && _getFormFields(fields, form);
      },
      formItemGroup: formItemGroup,
      stepsConfig: stepsConfig,
      onSubmit: handleSubmit,
      initialValues: _objectSpread({}, initialValues),
      parseTransform: parseTransform,
      displayLayout: displayLayout
    }));
  };
  // 可拖动及缩放
  if (dragAble) {
    return wrapSSR( /*#__PURE__*/_react.default.createElement(_StandardDragModal.DraggableModalProvider, null, /*#__PURE__*/_react.default.createElement(_StandardDragModal.DraggableModal, _extends({
      destroyOnHidden: true
      // destroyOnClose
      // @ts-ignore
      ,
      initialWidth: otherProps.width || _data.general.modalSize[size].width,
      initialHeight: otherProps.height,
      zIndex: 1001
    }, otherProps, {
      visible: visible,
      className: (0, _classnames.default)(componentName, 'standardModal', className, fieldStatus === 'viewOnly' ? 'is-view' : '', hashId),
      onCancel: handleCancel,
      afterClose: onAfterClose,
      onOk: handleSubmit,
      title: title,
      footer: renderFooter()
    }), renderChildrenNodes())));
  }
  return wrapSSR( /*#__PURE__*/_react.default.createElement(_antd.Modal
  // destroyOnClose
  , _extends({
    destroyOnHidden: true,
    maskClosable: false
    // @ts-ignore
    ,
    width: _data.general.modalSize[size].width
    // forceRender={type === 'form' || type === 'gridForm'}
  }, otherProps, {
    open: visible,
    title: title,
    footer: renderFooter(),
    className: (0, _classnames.default)(componentName, 'standardModal', className, fieldStatus === 'viewOnly' ? 'is-view' : '', hashId),
    style: _objectSpread({
      top: '80px'
    }, style)
    // bodyStyle={{ maxHeight: bodyMaxHeight, overflowY: 'scroll', ...bodyStyle }}
    ,
    styles: {
      body: _objectSpread({
        maxHeight: bodyMaxHeight + 'px',
        overflowX: 'hidden',
        overflowY: 'scroll'
      }, bodyStyle)
    },
    onCancel: handleCancel,
    afterClose: onAfterClose,
    onOk: handleSubmit
  }), renderChildrenNodes()));
};
var _default = exports.default = StandardModal;