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 _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; }
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); }
// @ts-nocheck
import React, { useContext, useEffect, useState, useMemo, useImperativeHandle } from 'react';
import { Form, Button } from 'antd';
import RenderItemGroup from "../FormComp/RenderItemGroup";
import { UtilValueFormat, splitArrayToSum } from "../utils";
import ButtonGroup from "../ButtonGroup/";
import { general } from "../data/";
import "./style/index.less";
import { FanContext } from "../ConfigContext";
import dayjs from "dayjs";
import useStyle from "./style/FilterStyle";
import SpecIcon from "../SpecIcon";
import { useLanguageObject } from "../hooks/use-language";
import { debounce } from "lodash";
var FormItem = Form.Item;
var StandardFilter = /*#__PURE__*/React.forwardRef(function (props, ref) {
  var lang = useLanguageObject(); // 当前使用的语言包
  var InitFanContext = useContext(FanContext);
  var providerConfig = InitFanContext['StandardFilter'] || {}; // 使用上下文（全局配置）设置扩展的配置项
  var _providerConfig$props = _objectSpread(_objectSpread({}, providerConfig), props),
    _providerConfig$props2 = _providerConfig$props.formItemGroup,
    formItemGroup = _providerConfig$props2 === void 0 ? [] : _providerConfig$props2,
    itemGroupConfig = _providerConfig$props.itemGroupConfig,
    initialValues = _providerConfig$props.initialValues,
    getFormFields = _providerConfig$props.getFormFields,
    onFilterSearch = _providerConfig$props.onFilterSearch,
    onFilterReset = _providerConfig$props.onFilterReset,
    onFilterChange = _providerConfig$props.onFilterChange,
    className = _providerConfig$props.className,
    style = _providerConfig$props.style,
    _providerConfig$props3 = _providerConfig$props.buttonGroup,
    buttonGroup = _providerConfig$props3 === void 0 ? [] : _providerConfig$props3,
    _providerConfig$props4 = _providerConfig$props.buttonGroupConfig,
    buttonGroupConfig = _providerConfig$props4 === void 0 ? {} : _providerConfig$props4,
    min = _providerConfig$props.min,
    codes = _providerConfig$props.codes,
    permissionCodes = _providerConfig$props.permissionCodes,
    confirmText = _providerConfig$props.confirmText,
    cancelText = _providerConfig$props.cancelText,
    _providerConfig$props5 = _providerConfig$props.confirmButtonProps,
    confirmButtonProps = _providerConfig$props5 === void 0 ? {} : _providerConfig$props5,
    _providerConfig$props6 = _providerConfig$props.cancelButtonProps,
    cancelButtonProps = _providerConfig$props6 === void 0 ? {} : _providerConfig$props6,
    filterButtonColSpan = _providerConfig$props.filterButtonColSpan,
    filterButtonConfig = _providerConfig$props.filterButtonConfig,
    _providerConfig$props7 = _providerConfig$props.formLayout,
    formLayout = _providerConfig$props7 === void 0 ? 'inline' : _providerConfig$props7,
    _providerConfig$props8 = _providerConfig$props.gridLayout,
    gridLayout = _providerConfig$props8 === void 0 ? 'inline' : _providerConfig$props8,
    _providerConfig$props9 = _providerConfig$props.buttonGroupPlacement,
    buttonGroupPlacement = _providerConfig$props9 === void 0 ? 'left' : _providerConfig$props9,
    filterFormStyle = _providerConfig$props.filterFormStyle,
    filterBtnsStyle = _providerConfig$props.filterBtnsStyle,
    _providerConfig$props10 = _providerConfig$props.colon,
    colon = _providerConfig$props10 === void 0 ? true : _providerConfig$props10,
    dateFormatter = _providerConfig$props.dateFormatter,
    _providerConfig$props11 = _providerConfig$props.collapseable,
    collapseable = _providerConfig$props11 === void 0 ? false : _providerConfig$props11,
    parseTransform = _providerConfig$props.parseTransform,
    _providerConfig$props12 = _providerConfig$props.actionsOrder,
    actionsOrder = _providerConfig$props12 === void 0 ? ['cancel', 'confirm', 'collapse'] : _providerConfig$props12,
    _providerConfig$props13 = _providerConfig$props.forceListener,
    forceListener = _providerConfig$props13 === void 0 ? true : _providerConfig$props13;
  var _Form$useForm = Form.useForm(),
    _Form$useForm2 = _slicedToArray(_Form$useForm, 1),
    filterForm = _Form$useForm2[0];
  // const filterFormRef = useRef<any>();
  // ref 的转发
  useImperativeHandle(ref, function () {
    return _objectSpread(_objectSpread({}, filterForm), {}, {
      onSubmit: function onSubmit(values) {
        return handleSearch(values);
      }
    });
  }, [filterForm]);
  var _useState = useState([]),
    _useState2 = _slicedToArray(_useState, 2),
    reFormItemGroup = _useState2[0],
    setReFormItemGroup = _useState2[1];
  var _useState3 = useState(24),
    _useState4 = _slicedToArray(_useState3, 2),
    isHideCount = _useState4[0],
    setIsHideCount = _useState4[1]; // 表单隐藏项数量值
  var _useState5 = useState(0),
    _useState6 = _slicedToArray(_useState5, 2),
    actionColSpan = _useState6[0],
    setActionColSpan = _useState6[1]; // 设置折叠后按钮组占用的栅格
  var _useState7 = useState(false),
    _useState8 = _slicedToArray(_useState7, 2),
    collapsed = _useState8[0],
    setCollapsed = _useState8[1];
  var componentName = 'spec-standard-filter';
  var _useStyle = useStyle(componentName),
    _useStyle2 = _slicedToArray(_useStyle, 2),
    wrapSSR = _useStyle2[0],
    hashId = _useStyle2[1];
  var filterFormLayout = useMemo(function () {
    return formLayout || 'inline';
  }, [formLayout]);

  // 计算当前栅格数量，及对应的size
  var columnNumberAndSize = useMemo(function () {
    // 当前栅栅数量
    var itemGroupSize = (itemGroupConfig === null || itemGroupConfig === void 0 ? void 0 : itemGroupConfig.size) || (filterFormLayout === 'horizontal' ? 'xxlg' : 'md');
    if (itemGroupConfig !== null && itemGroupConfig !== void 0 && itemGroupConfig.columnCount) {
      // 有配置栅格数 1,2,3,4
      switch (itemGroupConfig === null || itemGroupConfig === void 0 ? void 0 : itemGroupConfig.columnCount) {
        case 1:
          itemGroupSize = 'sm';
          break;
        case 2:
          itemGroupSize = 'md';
          break;
        case 3:
          itemGroupSize = 'lg';
          break;
        case 4:
          itemGroupSize = 'xxlg';
          break;
      }
    }
    return {
      columnNumber: general.modalSize[itemGroupSize].columnNumber,
      itemGroupSize: itemGroupSize
    };
  }, [itemGroupConfig, filterFormLayout]);

  // 计算表单隐藏项(开启展开与收缩）
  var calculateHideCount = function calculateHideCount(filterFormRef, groups) {
    var _effectiveLastRowGrou;
    var itemGroupSize = columnNumberAndSize.itemGroupSize,
      columnNumber = columnNumberAndSize.columnNumber;
    var formValues = filterFormRef === null || filterFormRef === void 0 ? void 0 : filterFormRef.getFieldValue();
    var colsArr = [];
    groups.forEach(function (gItem) {
      if (!(gItem !== null && gItem !== void 0 && gItem.isHidden || (gItem.hasOwnProperty('isHide') ? typeof gItem.isHide === 'function' ? gItem.isHide(_objectSpread({}, formValues), _objectSpread({
        current: filterFormRef
      }, filterFormRef)) : gItem.isHide : false))) {
        if (gItem.hasOwnProperty('colSpan')) {
          colsArr.push(gItem.colSpan);
        } else {
          if (gItem.hasOwnProperty('display')) {
            // side返回当前栅格数量；block/{labelCol:{ span: 4 }, wrapperCol: { span: 19}} 则返回24/栅格列数
            colsArr.push(_typeof(gItem.display) === 'object' || gItem.display === 'block' ? 24 : 24 / columnNumber);
          } else {
            colsArr.push(24 / columnNumber);
          }
        }
      }
    });
    var effectiveLastRowGroup = splitArrayToSum(colsArr, 24);
    // 计算最后一个数组之和
    setActionColSpan((_effectiveLastRowGrou = effectiveLastRowGroup[effectiveLastRowGroup.length - 1]) === null || _effectiveLastRowGrou === void 0 ? void 0 : _effectiveLastRowGrou.reduce(function (acc, num) {
      return acc + num;
    }, 0));
    return;
    // Rule1: 不包括isHidden跟isHide的数据
    // Rule2：剩余的表单项中，查找是否有自定义配置 display='block' 或者colSpan的表单项
    var notShowGroupItem = (groups || []).filter(function (item) {
      return (item === null || item === void 0 ? void 0 : item.isHidden) || (item.hasOwnProperty('isHide') ? item.isHide(_objectSpread({}, formValues), _objectSpread({
        current: filterFormRef
      }, filterFormRef)) : false);
    });
    // 可显示的表单值
    var showGroupItem = (groups || []).filter(function (item) {
      return !(item !== null && item !== void 0 && item.isHidden || (item.hasOwnProperty('isHide') ? item.isHide(_objectSpread({}, formValues), _objectSpread({
        current: filterFormRef
      }, filterFormRef)) : false));
    });
    var showGroupWithSetting = showGroupItem.filter(function (item) {
      return item.hasOwnProperty('colSpan');
    }); // 指定设置数量
    // const showDefaultWithSetting = showGroupItem.filter(item => !item.hasOwnProperty('colSpan')) // 指定设置数量
    var resultCount = notShowGroupItem.length;
    var aCount = 0; // 需要再次额外新增的数量
    // console.log('showGroupWithSetting', showGroupWithSetting, 'showDefaultWithSetting', showDefaultWithSetting)
    if (showGroupWithSetting.length > 0) {
      showGroupWithSetting.forEach(function (gItem) {
        // colSpan 优先级更高
        if (gItem.hasOwnProperty('colSpan')) {
          // console.log('有配置了colSpan=' + gItem.colSpan + '占用栅格数量', gItem.colSpan / (24 / columnNumber), '需要再额外减1', gItem.colSpan / (24 / columnNumber) - 1, Math.ceil(gItem.colSpan / (24 / columnNumber) - 1))
          aCount += Math.ceil(gItem.colSpan / (24 / columnNumber) - 1); // 额外占用了（如果4列的情况，前面有三列占用，colSpan配置了两列占用，则在此处不要减1）
          return;
        }
        if (gItem.hasOwnProperty('display') && gItem.display === 'block') {
          // TODO.计算会有问题
          // console.log('有配置了display=block', Math.ceil(24 / (24 / columnNumber) - 1))
          // aCount += columnNumber -1 // Math.ceil(24 / (24 / columnNumber) - 1)  // 额外占用了
        }
      });
    }
    setIsHideCount(resultCount - aCount);
  };

  //  配置筛选按钮（确认与取消）
  var filterActionButtons = useMemo(function () {
    var itemGroupSize = columnNumberAndSize.itemGroupSize,
      columnNumber = columnNumberAndSize.columnNumber;
    // 计算扣除栅格列数是否还有多余的项，用来判断筛选按钮的版式（初始化的时候，可能会受默认值内配置的isHide影响导致计算错误;或自定义表单控件组栅格影响）
    // if (collapseable) {
    //   columnNumber = collapsed ? columnNumber : (columnNumber === 1 ? columnNumber = 2 : columnNumber)
    // }
    // let calculateTimes = (reFormItemGroup.length - isHideCount) % columnNumber
    // console.log('当前多余的数量', calculateTimes, '当前隐藏的控件数量isHideCount==>', isHideCount, itemGroupSize, 'columnNumber', columnNumber)
    // xs:1列  sm:1列   【span:24】
    // md:2列           【span:12】
    // lg:3列  xlg:3列  【span:8】
    // xxlg:4列         【span:6】
    if (!onFilterSearch && !onFilterReset) return [];
    return [_objectSpread(_objectSpread({
      label: '',
      type: 'custom',
      // display: 'block',
      filedName: 'filterAction',
      display: {
        wrapperCol: {
          // 占用的格子数按对应size配置的formItem,如果是md则单独使用筛选的栅格配置
          span: itemGroupSize === 'md' || itemGroupSize === 'lg' || itemGroupSize === 'xlg' ? general.modalSize[itemGroupSize].filterFormLayout.labelCol.span + general.modalSize[itemGroupSize].filterFormLayout.wrapperCol.span : general.modalSize[itemGroupSize].formLayout.labelCol.span + general.modalSize[itemGroupSize].formLayout.wrapperCol.span
        }
      },
      style: {
        // textAlign: 'right'
      },
      protoFormItem: {
        style: {
          textAlign: filterFormLayout === 'horizontal' ? 'right' : 'left'
        },
        className: filterFormLayout === 'horizontal' ? 'filter-action-right' : 'filter-action-left'
      },
      colSpan: filterButtonColSpan || 24 - actionColSpan
    }, filterButtonConfig), {}, {
      customRender: function customRender() {
        return /*#__PURE__*/React.createElement(FormItem, {
          noStyle: true
        }, (actionsOrder || []).map(function (item, index) {
          if (item === 'cancel') {
            return onFilterReset && /*#__PURE__*/React.createElement(Button, _extends({
              type: "primary",
              key: item,
              style: index === 0 ? {} : {
                marginLeft: 8
              },
              onClick: handleReset,
              ghost: true
            }, cancelButtonProps), cancelText || (lang === null || lang === void 0 ? void 0 : lang['filter.reset']) || '重置');
          }
          if (item === 'confirm') {
            return onFilterSearch && /*#__PURE__*/React.createElement(Button, _extends({
              type: "primary",
              key: item,
              style: index === 0 ? {} : {
                marginLeft: 8
              },
              htmlType: "submit"
            }, confirmButtonProps), confirmText || (lang === null || lang === void 0 ? void 0 : lang['filter.submit']) || '查询');
          }
          if (item === 'collapse') {
            return filterFormLayout === 'horizontal' && collapseable && reFormItemGroup.length > columnNumberAndSize.columnNumber - 1 ? /*#__PURE__*/React.createElement(Button, {
              key: item,
              type: 'link',
              onClick: function onClick() {
                return setCollapsed(!collapsed);
              },
              style: {
                marginLeft: 8,
                paddingInlineStart: 0,
                paddingInlineEnd: 0
              }
            }, collapsed ? (lang === null || lang === void 0 ? void 0 : lang['field.collapse']) || '收起' : (lang === null || lang === void 0 ? void 0 : lang['field.expand']) || '展开', /*#__PURE__*/React.createElement(SpecIcon, {
              noPrefix: true,
              name: collapsed ? 'speci-up' : 'speci-down'
            })) : null;
          }
          return null;
        }));
      }
    })];
  }, [confirmText, cancelText, filterFormLayout, reFormItemGroup, onFilterSearch, onFilterReset, columnNumberAndSize, filterForm, isHideCount, collapseable, collapsed, actionsOrder]);

  // 更新表单控件值，用于外部获取当前表单实例(force是否强制清空表单)
  var updateFormFields = function updateFormFields(newVal, force) {
    var resetValues = {};
    if (force) {
      // this.filterFormRef.current.resetFields()
      // 先清空 再赋值
      resetValues = filterForm.getFieldsValue();
      Object.keys(resetValues).forEach(function (item) {
        resetValues[item] = undefined;
      });
    }
    var dateFieldTypes = ['datePicker', 'dateTimePicker', 'rangePicker', 'rangeTimePicker', 'timePicker', 'timePickerRange', 'dateTimeRangePicker'];
    var filterDateFields = formItemGroup.filter(function (fItem) {
      return dateFieldTypes.includes(fItem.type);
    });
    if (parseTransform) {
      newVal = parseTransform(_objectSpread({}, newVal));
    }
    // 如果配置了dateFormatter='string'，则将默认对其他进行格式转换
    if (dateFormatter === 'string') {
      // 需要将字符串转换成日期格式
      filterDateFields.forEach(function (dItem) {
        if (newVal[dItem.filedName || dItem.fieldName]) {
          if (typeof newVal[dItem.filedName || dItem.fieldName] === 'string') {
            // console.log('将字符串转换成dayjs')
            newVal[dItem.filedName || dItem.fieldName] = dayjs(newVal[dItem.filedName || dItem.fieldName]);
          } else if (Array.isArray(newVal[dItem.filedName || dItem.fieldName])) {
            // console.log('将数组转换成dayjs数组')
            newVal[dItem.filedName || dItem.fieldName] = newVal[dItem.filedName || dItem.fieldName].map(function (valItem) {
              return typeof valItem === 'string' ? dayjs(valItem) : valItem;
            });
          } else if (dItem.type === 'dateTimeRangePicker') {
            var _newVal;
            newVal[dItem.filedName || dItem.fieldName] = _objectSpread(_objectSpread({}, newVal[dItem.filedName || dItem.fieldName]), {}, {
              dateTime: (((_newVal = newVal[dItem.filedName || dItem.fieldName]) === null || _newVal === void 0 ? void 0 : _newVal.dateTime) || []).map(function (valItem) {
                return typeof valItem === 'string' ? dayjs(valItem) : valItem;
              })
            });
            console.log('时间区间范围', newVal[dItem.filedName || dItem.fieldName]);
            // console.log('其他情况',newVal[dItem.filedName],  newVal[dItem.filedName] instanceof Date)
            // console.log('其他情况,当它是日期格式，则不进行转换')
          } else {
            console.log('其他情况', newVal[dItem.filedName], newVal[dItem.filedName] instanceof Date);
            // console.log('其他情况,当它是日期格式，则不进行转换')
          }
        }
      });
    }
    filterForm.setFieldsValue(_objectSpread(_objectSpread({}, resetValues), newVal || {})); // 直接清空表单的赋值
    forceUpdateForm();
  };
  // 强制更新表单值，用于赋初始化实例值
  var forceUpdateForm = function forceUpdateForm() {
    var formValues = filterForm.getFieldsValue();
    if (Object.prototype.hasOwnProperty.call(formValues, false)) {
      delete formValues.false; // 自定义结构会莫名的出来一个false字段
    }
    // calculateHideCount(filterForm, reFormItemGroup)
    // 更新当前表单数量，排除被隐藏的值
    if (filterFormLayout === "horizontal") {
      updateGroupByCollapsed(formItemGroup, formValues).then(function (groups) {
        setReFormItemGroup(groups);
        calculateHideCount(filterForm, groups);
      });
    }
    if (getFormFields) getFormFields(formValues, _objectSpread({
      current: filterForm
    }, filterForm));
  };

  // 强制更新表单值，用于赋初始化实例值
  var handleFieldsChange = debounce(function (fieldValue) {
    var formValues = filterForm.getFieldsValue();
    if (Object.prototype.hasOwnProperty.call(formValues, false)) {
      delete formValues.false; // 自定义结构会莫名的出来一个false字段
    }
    // 过滤隐藏掉的表单项
    var resultValues = UtilValueFormat(formValues, reFormItemGroup, dateFormatter);
    // filterForm?.setFieldsValue(resultValues)
    onFilterChange === null || onFilterChange === void 0 || onFilterChange(resultValues, fieldValue);
  });
  var handleSearch = debounce(function (values) {
    if (Object.prototype.hasOwnProperty.call(values, false)) {
      delete values.false; // 自定义结构会莫名的出来一个false字段
    }
    var resultValues = UtilValueFormat(values, reFormItemGroup, dateFormatter);
    // reFormItemGroup里面有 transform，则筛选转换
    // console.log('格式化前数据', values)
    // console.log('格式化后数据', resultValues)
    if (onFilterSearch) {
      onFilterSearch(_objectSpread({}, resultValues));
    }
  }, 300);
  var handleReset = function handleReset() {
    filterForm.resetFields();
    // 使用此方法，表单校验无法清空掉，所以需要先重置resetFields()
    var resetValues = filterForm.getFieldsValue();
    Object.keys(resetValues).forEach(function (item) {
      resetValues[item] = undefined;
    });
    filterForm.setFieldsValue(_objectSpread({}, resetValues)); // 直接清空表单的赋值
    // filterForm.resetFields()  // 单独用此方法无效，所以先清空+设置所有值为undefined
    setReFormItemGroup(formItemGroup); // 重新渲染列表
    calculateHideCount(filterForm, reFormItemGroup);
    if (onFilterReset) {
      onFilterReset(filterForm === null || filterForm === void 0 ? void 0 : filterForm.getFieldsValue());
    }
  };

  // 判断是否隐藏结构, display:'none'
  var setItemHiddenNode = function setItemHiddenNode(item, index, collapsed, showItemNumber) {
    // console.log('判断是否隐藏结构==>当前执行序号', index, showItemNumber)
    if (item.filedName === 'filterAction' || item.fieldName === 'filterAction') {
      return {
        isHidden: false
      };
    }
    return {
      // 栅格列为1时，显示1个表单项
      isHidden: collapsed ? false : showItemNumber === 0 ? index !== 0 : !(index < showItemNumber)
    };
  };
  // 渲染隐藏指定控件
  var itemIsHide = function itemIsHide(isHide, getFieldsValue, FormInstance) {
    if (typeof isHide === 'function') {
      return isHide(getFieldsValue, FormInstance, 'default');
    }
    return isHide || false;
  };
  /**
   * 更新折叠状态
   * */
  var updateGroupByCollapsed = function updateGroupByCollapsed(groups, formValues) {
    var showItemNumber = columnNumberAndSize.columnNumber - 1;
    return new Promise(function (resolve, reject) {
      if (Array.isArray(groups)) {
        resolve(groups.map(function (item, index) {
          if (collapseable && filterFormLayout === "horizontal") {
            var _setItemHiddenNode = setItemHiddenNode(item, index, collapsed, showItemNumber),
              isHidden = _setItemHiddenNode.isHidden;
            item.isHidden = isHidden;
            item.style = _objectSpread(_objectSpread({}, item.style || {}), {}, {
              display: item.isHidden ? 'none' : 'block'
            });
            if (item.hasOwnProperty('isHide') && itemIsHide(item.isHide, formValues, _objectSpread({
              current: filterForm
            }, filterForm))) {
              showItemNumber++;
              item.isHidden = true;
              // console.log('当前是结构是隐藏未渲染,跳到下个序号', showItemNumber)
            }
          }
          return _objectSpread({}, item);
        }));
      } else {
        resolve(groups);
      }
    });
  };
  useEffect(function () {
    // 初始化表单数据数据
    if (collapseable && filterFormLayout === "horizontal") {
      var formValues = filterForm === null || filterForm === void 0 ? void 0 : filterForm.getFieldValue();
      updateGroupByCollapsed(formItemGroup, formValues).then(function (groups) {
        setReFormItemGroup(groups);
        calculateHideCount(filterForm, groups);
      });
    } else {
      setReFormItemGroup(formItemGroup);
    }
  }, [formItemGroup, collapseable, filterFormLayout, collapsed, columnNumberAndSize === null || columnNumberAndSize === void 0 ? void 0 : columnNumberAndSize.columnNumber, itemGroupConfig, filterForm]);

  // 如果不监听initialValues的话，可能url上的search更改时表单无法清空，需要自行手动重置
  useEffect(function () {
    if (!forceListener) {
      if (initialValues && JSON.stringify(initialValues) !== '{}') {
        updateFormFields(initialValues, true);
      }
    }
  }, [forceListener, filterForm]);
  useEffect(function () {
    if (forceListener) {
      if (initialValues && JSON.stringify(initialValues) !== '{}') {
        updateFormFields(initialValues, true);
      }
    }
  }, [forceListener, initialValues]);
  // 如果不监听initialValues的话，可能url上的search更改时表单无法清空
  // useEffect(() => {
  //   if (filterForm) {   // <---- check ref before use the form instance
  //     if (initialValues && typeof initialValues === 'object') {
  //       updateFormFields(initialValues, true)
  //     }
  //   }
  // }, [filterForm]);
  // / 表单列表组 formItemGroup 类型为数组或者React.Node
  var renderFormItemGroup = function renderFormItemGroup() {
    if (Array.isArray(reFormItemGroup)) {
      // 数组则默认加上"确认与取消"按钮
      return /*#__PURE__*/React.createElement(RenderItemGroup, _extends({
        itemGroup: reFormItemGroup.concat(filterActionButtons),
        size: filterFormLayout === 'horizontal' ? 'xxlg' : 'md' // size决定栅格排列数量(4列排版）
        ,
        layout: filterFormLayout,
        form: filterForm,
        collapseable: collapseable,
        collapsed: collapsed,
        parentNode: 'standardFilter'
        // displayLayout={{labelCol: { span: 8 }, wrapperCol: { span: 16 },}}
        ,
        doUpdateFormFields: function doUpdateFormFields() {
          return forceUpdateForm();
        }
      }, itemGroupConfig, {
        onFieldsChange: handleFieldsChange
      }));
    }
    return reFormItemGroup;
  };
  /**
   * 生成guid
   */
  var guid = function guid() {
    function S4() {
      return ((1 + Math.random()) * 0x10000 | 0).toString(16).substring(1);
    }
    return "".concat(S4(), "-").concat(S4());
  };
  var renderButtonGroup = function renderButtonGroup() {
    return buttonGroup && buttonGroup.length > 0 ? /*#__PURE__*/React.createElement("div", {
      className: "filter-btns filter-btns-".concat(gridLayout, " filter-btns-").concat(gridLayout, "-").concat(buttonGroupPlacement),
      style: filterBtnsStyle
    }, /*#__PURE__*/React.createElement(ButtonGroup, _extends({
      options: buttonGroup,
      min: min,
      codes: codes,
      permissionCodes: permissionCodes
    }, buttonGroupConfig))) : null;
  };
  return wrapSSR( /*#__PURE__*/React.createElement(Form, {
    name: 'standard-filter-form-' + guid()
    // ref={filterFormRef}
    ,
    form: filterForm,
    layout: filterFormLayout,
    onFinish: handleSearch
    // className={classNames(componentName, hashId, props?.className)}
    ,
    className: "standard-filter ".concat(componentName, " ").concat(className || '', " ").concat(hashId),
    style: style,
    colon: colon
    // {...providerConfig}  // 直接传这里面的话，会影响layout渲染
    //     initialValues={parseTransform ? parseTransform(initialValues) : initialValues}
  }, /*#__PURE__*/React.createElement("div", {
    className: "filter-grid filter-grid-".concat(gridLayout),
    style: filterFormStyle
  }, reFormItemGroup.length === 0 ? null : /*#__PURE__*/React.createElement("div", {
    className: "filter-form filter-form-".concat(formLayout)
  }, reFormItemGroup ? /*#__PURE__*/React.createElement(React.Fragment, null, renderFormItemGroup()) : null), renderButtonGroup())));
});
export default StandardFilter;