import "antd/es/badge/style";
import _Badge from "antd/es/badge";
import "@parallel-line/common/es/common/tag/style";
import _Tag from "@parallel-line/common/es/common/tag";
import "antd/es/tooltip/style";
import _Tooltip from "antd/es/tooltip";
import "antd/es/empty/style";
import _Empty from "antd/es/empty";
import "antd/es/form/style";
import _Form from "antd/es/form";
var _excluded = ["size", "rowKey", "rowSelection", "dataSource", "externalQueryDic", "actions", "columns", "actionConfig", "className", "filterIsEmpty", "hideAllFilter", "prefixCls", "filteredValues", "defaultColumnConfig", "renderColumn", "renderTitle", "renderFilter", "onFilteredChange", "onCleanFiltered", "onLinkClick", "onActionClick", "actionRule"],
    _excluded2 = ["children"],
    _excluded3 = ["value", "key"];

function _toArray(arr) { return _arrayWithHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableRest(); }

function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }

function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }

function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }

function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }

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

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (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 = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { 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 _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(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }

function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }

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; }

/* eslint-disable func-names */

/* eslint-disable @typescript-eslint/no-use-before-define */

/* eslint-disable no-nested-ternary */
import React, { useEffect, useRef } from 'react';
import Table from 'antd/es/table';
import classnames from 'classnames';
import { useHistory, useMemoDeep } from '@parallel-line/hooks';
import { forwardRef, useImperativeHandle } from 'react';
import { isNumber, isNil, isFunction, isObject, uniqueId } from 'lodash-es';
import { calc, getDic, unitTransform, toTime } from '@parallel-line/utils';
import { SearchOutlined, DownOutlined } from '@parallel-line/icons';
import Input from '../input';
import Action from './Action';
import Button from '../button';
import Select from '../select';
import FilterItem from './FilterItem';
import CitySelect from '../city-select';
import InputNumber from '../input-number';
import DateRangePicker from './DateRangePicker';
import { devWarning, getPathValue, toRoute } from '@parallel-line/common/es/utils';
import { DateTimeColWidth, CityColWidth, ActionColWidth, EmptyText } from './constant';
var ColumnGroup = Table.ColumnGroup,
    Column = Table.Column;
/**
 * 判断是否空数据
 * @param any
 * @returns
 */

var isEmpty = function isEmpty(any) {
  try {
    if (isNumber(any)) return false;
    return isNil(any) || any === '';
  } catch (e) {
    return true;
  }
};

var InlineTable = /*#__PURE__*/forwardRef(function (props, ref) {
  var size = props.size,
      rowKey = props.rowKey,
      rowSelection = props.rowSelection,
      _props$dataSource = props.dataSource,
      dataSource = _props$dataSource === void 0 ? [] : _props$dataSource,
      _props$externalQueryD = props.externalQueryDic,
      externalQueryDic = _props$externalQueryD === void 0 ? {} : _props$externalQueryD,
      _props$actions = props.actions,
      actions = _props$actions === void 0 ? [] : _props$actions,
      _props$columns = props.columns,
      columns = _props$columns === void 0 ? [] : _props$columns,
      _props$actionConfig = props.actionConfig,
      actionConfig = _props$actionConfig === void 0 ? {} : _props$actionConfig,
      className = props.className,
      filterIsEmpty = props.filterIsEmpty,
      hideAllFilter = props.hideAllFilter,
      pCls = props.prefixCls,
      _props$filteredValues = props.filteredValues,
      filteredValues = _props$filteredValues === void 0 ? {} : _props$filteredValues,
      _props$defaultColumnC = props.defaultColumnConfig,
      defaultColumnConfig = _props$defaultColumnC === void 0 ? {} : _props$defaultColumnC,
      renderColumnEvent = props.renderColumn,
      renderTitle = props.renderTitle,
      renderFilter = props.renderFilter,
      _props$onFilteredChan = props.onFilteredChange,
      onFilteredChange = _props$onFilteredChan === void 0 ? function () {} : _props$onFilteredChan,
      _props$onCleanFiltere = props.onCleanFiltered,
      onCleanFiltered = _props$onCleanFiltere === void 0 ? function () {} : _props$onCleanFiltere,
      _props$onLinkClick = props.onLinkClick,
      onLinkClick = _props$onLinkClick === void 0 ? function () {} : _props$onLinkClick,
      _props$onActionClick = props.onActionClick,
      onActionClick = _props$onActionClick === void 0 ? function () {} : _props$onActionClick,
      _props$actionRule = props.actionRule,
      actionRule = _props$actionRule === void 0 ? function () {
    return [false, false];
  } : _props$actionRule,
      tableProps = _objectWithoutProperties(props, _excluded);

  var prefixCls = "".concat(pCls, "-table");

  var _Form$useForm = _Form.useForm(),
      _Form$useForm2 = _slicedToArray(_Form$useForm, 1),
      form = _Form$useForm2[0];

  var history = useHistory();
  var tableRef = useRef(null); // const emptyRef = useRef<HTMLDivElement>(null);

  var noData = useMemoDeep(function () {
    return !dataSource.length;
  }, [dataSource]);
  var firstColumnKey = useMemoDeep(function () {
    var _columns$;

    return (_columns$ = columns[0]) === null || _columns$ === void 0 ? void 0 : _columns$.key;
  }, [columns]);

  var rowKeyFn = function rowKeyFn(record) {
    var _key = '';

    if (typeof rowKey === 'function') {
      try {
        _key = rowKey(record);
      } catch (error) {
        console.error(error);
        _key = uniqueId();
      }
    }

    if (typeof rowKey === 'string') {
      _key = record[rowKey];
    }

    if (!_key) {
      _key = uniqueId();
    }

    return _key;
  };

  if (defaultColumnConfig.unitInTitle == null) {
    defaultColumnConfig.unitInTitle = true;
  }

  if (tableProps.pagination) {
    var _tableProps$paginatio;

    tableProps.pagination.prefixCls = "".concat(prefixCls, "-pagination");

    if (!((_tableProps$paginatio = tableProps.pagination) === null || _tableProps$paginatio === void 0 ? void 0 : _tableProps$paginatio.simple)) {
      var _tableProps$paginatio2 = tableProps.pagination,
          current = _tableProps$paginatio2.current,
          pageSize = _tableProps$paginatio2.pageSize;
      tableProps.pagination.size = 'default';

      tableProps.pagination.showTotal = function (total) {
        if (noData) return '共0条记录';
        return "\u5171".concat(total, "\u6761\u8BB0\u5F55 \u7B2C").concat(current, " / ").concat(Math.ceil(calc("".concat(total, " / ").concat(pageSize))), "\u9875");
      };
    }
  }

  useImperativeHandle(ref, function () {
    return {
      container: tableRef.current
    };
  });
  useEffect(function () {
    if (filteredValues) {
      form.setFieldsValue(filteredValues);
    }
  }, [filteredValues]); // TODO 针对 CitySelect 没有清空事件的处理方式

  /** 城市筛选字段集合 */

  var filteredCitys = useMemoDeep(function () {
    return columns.filter(function (column) {
      return column.type === 'City';
    }).map(function (column) {
      return column.key;
    });
  }, [columns]);

  var onValuesChange = function onValuesChange(changeValues) {
    Object.entries(changeValues).forEach(function (_ref) {
      var _ref2 = _slicedToArray(_ref, 2),
          key = _ref2[0],
          value = _ref2[1];

      if (filteredCitys.includes(key) && !value) {
        onFilteredChange(key, value);
      }
    });
  };

  var renderColumn = function renderColumn(_ref3, index) {
    var children = _ref3.children,
        col = _objectWithoutProperties(_ref3, _excluded2);

    var unit = col.unit,
        type = col.type,
        dicKey = col.dicKey,
        sorter = col.sorter,
        _col$fieldProps = col.fieldProps,
        fieldProps = _col$fieldProps === void 0 ? {} : _col$fieldProps,
        _col$hideInSearch = col.hideInSearch,
        hideInSearch = _col$hideInSearch === void 0 ? defaultColumnConfig.hideInSearch : _col$hideInSearch,
        _col$unitInTitle = col.unitInTitle,
        unitInTitle = _col$unitInTitle === void 0 ? defaultColumnConfig.unitInTitle : _col$unitInTitle;
    var SearchTitle = null;
    var placeholder = "\u641C\u7D22".concat(col.title);
    var title = col.title;

    var columnProps = _objectSpread({}, col);

    columnProps.width = col.width;
    columnProps.fixed = col.fixed;

    if (noData) {
      columnProps.ellipsis = false;
    }

    if (unit && unitInTitle) title = "".concat(title, " (").concat(unit, ")");

    if (renderTitle) {
      columnProps.title = function (titleProps) {
        return renderTitle(titleProps, title, col.key, col);
      };
    } else columnProps.title = title;

    if (sorter) {
      columnProps.sorter = {
        multiple: index
      };
    }

    if (type === 'Date') {
      columnProps.width = columnProps.width || DateTimeColWidth;
    } else if (type === 'City') {
      columnProps.width = columnProps.width || CityColWidth;
    }

    if (!hideInSearch) {
      var handleFilteredChange = function handleFilteredChange() {
        var value = form.getFieldValue(col.key);
        onFilteredChange(col.key, value);
      };

      if (dicKey || col.options) {
        var list = col.options || [];

        if (dicKey) {
          list = getDic(dicKey).map(function (_ref4) {
            var value = _ref4.value,
                key = _ref4.key,
                rest = _objectWithoutProperties(_ref4, _excluded3);

            return _objectSpread({
              text: value,
              value: key
            }, rest);
          });
        }

        SearchTitle = /*#__PURE__*/React.createElement(Select, Object.assign({
          noWrap: true,
          allowClear: true,
          placeholder: placeholder,
          bordered: false,
          style: {
            width: '100%'
          },
          onChange: handleFilteredChange,
          filterOption: function filterOption(inputValue, option) {
            if (typeof (option === null || option === void 0 ? void 0 : option.children) === 'string') {
              var _option$children;

              return (option === null || option === void 0 ? void 0 : (_option$children = option.children) === null || _option$children === void 0 ? void 0 : _option$children.search(inputValue)) >= 0;
            }

            return false;
          }
        }, fieldProps), list.map(function (item) {
          return /*#__PURE__*/React.createElement(Select.Option, {
            key: item.value,
            value: item.value
          }, item.text);
        }));
      } else {
        switch (type) {
          case 'Number':
            // TODO: 数值区间筛选
            break;

          case 'Numbering':
            SearchTitle = /*#__PURE__*/React.createElement(InputNumber, Object.assign({
              hideStep: true,
              selectInFocus: true,
              allowClear: false,
              bordered: false,
              placeholder: placeholder,
              suffix: /*#__PURE__*/React.createElement(SearchOutlined, {
                onClick: handleFilteredChange
              }),
              onClose: handleFilteredChange,
              onPressEnter: handleFilteredChange
            }, fieldProps));
            break;

          case 'City':
            SearchTitle = /*#__PURE__*/React.createElement(CitySelect, Object.assign({
              placeholder: placeholder,
              style: {
                width: '100%'
              },
              bordered: false,
              allowClear: true,
              suffixIcon: /*#__PURE__*/React.createElement(DownOutlined, null),
              onPopupVisibleChange: function onPopupVisibleChange(popupVisible) {
                return !popupVisible && handleFilteredChange();
              }
            }, fieldProps));
            break;

          case 'Date':
            SearchTitle = /*#__PURE__*/React.createElement(DateRangePicker, Object.assign({
              bordered: false,
              onChange: function onChange() {
                return onFilteredChange(col.key, form.getFieldValue(col.key) || []);
              }
            }, fieldProps));
            break;

          default:
            SearchTitle = /*#__PURE__*/React.createElement(Input, Object.assign({
              selectInFocus: true,
              bordered: false,
              allowClear: false,
              placeholder: placeholder,
              suffix: /*#__PURE__*/React.createElement(SearchOutlined, {
                onClick: handleFilteredChange
              }),
              onClose: handleFilteredChange,
              onPressEnter: handleFilteredChange
            }, fieldProps));
            break;
        }
      }

      if (isFunction(renderFilter)) {
        var node = renderFilter({
          key: col.key,
          col: col,
          dataSource: dataSource,
          node: SearchTitle,
          handleFilteredChange: handleFilteredChange
        });
        SearchTitle = /*#__PURE__*/React.isValidElement(node) ? node : SearchTitle;
      }
    }

    if (SearchTitle) {
      SearchTitle = /*#__PURE__*/React.createElement(FilterItem, {
        prefixCls: prefixCls,
        name: col.key
      }, SearchTitle);
    } else {
      SearchTitle = /*#__PURE__*/React.createElement("div", {
        className: "".concat(prefixCls, "-filter-empty-item")
      });
    }

    if (hideAllFilter || filterIsEmpty) return /*#__PURE__*/React.createElement(Column, Object.assign({}, columnProps, {
      key: col.key,
      render: function render(text, record, inx) {
        return columnRender(record, inx, col);
      }
    }));
    return /*#__PURE__*/React.createElement(ColumnGroup, Object.assign({}, columnProps, {
      key: col.key
    }), /*#__PURE__*/React.createElement(Column, Object.assign({}, columnProps, {
      key: col.key,
      title: SearchTitle,
      sorter: false,
      filtered: false,
      className: "".concat(prefixCls, "-search"),
      render: function render(text, record, inx) {
        return columnRender(record, inx, col);
      }
    })));
  };

  var columnRender = function columnRender(record, index, col) {
    if (noData) {
      if (col.key === firstColumnKey) {
        var _tableRef$current, _props$locale;

        var colSpan = columns.length + 1;
        if (!filterIsEmpty || actions.length > 0) colSpan += 1; // TODO 具备选中行时需考虑怎么呈现

        return {
          props: {
            colSpan: colSpan,
            className: className
          },
          children: /*#__PURE__*/React.createElement("div", {
            className: "ant-table-expanded-row-fixed",
            style: {
              width: (_tableRef$current = tableRef.current) === null || _tableRef$current === void 0 ? void 0 : _tableRef$current.clientWidth,
              position: 'sticky',
              left: 0,
              overflow: 'hidden'
            }
          }, ((_props$locale = props.locale) === null || _props$locale === void 0 ? void 0 : _props$locale.emptyText) || /*#__PURE__*/React.createElement(_Empty, {
            image: _Empty.PRESENTED_IMAGE_SIMPLE
          }))
        };
      }

      return {
        props: {
          colSpan: 0
        }
      };
    }

    var key = col.dataIndex || col.key;
    var text = getPathValue(record, key);
    text = columnTextRender(text, col);

    if (text === EmptyText) {
      text = columnEllipsisRender(text, col);

      if (isFunction(renderColumnEvent)) {
        return renderColumnEvent({
          text: text,
          record: record,
          index: index,
          dataSource: dataSource
        }, col.key, col);
      }

      return text;
    }

    if (col.type === 'Link') {
      return /*#__PURE__*/React.createElement(Button, {
        type: "link",
        size: "small",
        style: {
          padding: 0
        },
        onClick: function onClick() {
          if (col.linkClick) {
            var mergedQueryDic = _objectSpread(_objectSpread({}, externalQueryDic), {}, {
              record: record
            });

            toRoute(history, mergedQueryDic, col.linkClick);
          } else onLinkClick(text, record, col.key);
        }
      }, text);
    }

    if (isFunction(renderColumnEvent)) {
      text = renderColumnEvent({
        text: text,
        record: record,
        index: index,
        dataSource: dataSource
      }, col.key, col); // TODO 临时判断是否是 RenderedCell 类型

      if (text && isObject(text) && text.props && !text.type) {
        return {
          props: text.props,
          children: columnEllipsisRender(text.children, col)
        };
      }
    }

    return columnEllipsisRender(text, col);
  };

  var columnEllipsisRender = function columnEllipsisRender(text, col) {
    var width = col.width ? typeof col.width === 'number' ? col.width + 'px' : col.width : undefined;
    var style = {
      width: col.width ? "calc(".concat(width, " - 24px)") : undefined,
      maxWidth: width,
      color: 'inherit',
      padding: 0,
      margin: 0,
      textAlign: col.align || 'left',
      overflow: 'hidden',
      textOverflow: 'ellipsis',
      whiteSpace: 'nowrap'
    }; // if (col.ellipsis) {
    //   if (['number', 'string'].includes(typeof text)) {
    //     text = (
    //       <Typography.Paragraph
    //         style={style}
    //         ellipsis={{ rows: 1, tooltip: true }}
    //       >
    //         {`${text}`}
    //       </Typography.Paragraph>
    //     );
    //   }
    // }

    if (col.ellipsis && text !== EmptyText) {
      if (['number', 'string'].includes(_typeof(text))) {
        return /*#__PURE__*/React.createElement(_Tooltip, {
          title: text
        }, /*#__PURE__*/React.createElement("div", {
          style: style
        }, text));
      }
    }

    return /*#__PURE__*/React.createElement("div", {
      style: style
    }, text);
  };

  var columnTextRender = function columnTextRender(text, col, ellipsisFn) {
    var type = col.type,
        valueType = col.valueType,
        unit = col.unit,
        _col$unitInTitle2 = col.unitInTitle,
        unitInTitle = _col$unitInTitle2 === void 0 ? true : _col$unitInTitle2;
    var dicItem;

    if (isEmpty(text)) {
      return EmptyText;
    }

    if (getDic && col.dicKey) {
      var _dicItem;

      var D = getDic(col.dicKey, text);
      dicItem = _objectSpread(_objectSpread({}, D), {}, {
        text: D.value,
        value: D.key
      });
      text = (_dicItem = dicItem) === null || _dicItem === void 0 ? void 0 : _dicItem.text;
    } else if (col.options && col.options.length > 0) {
      dicItem = col.options.find(function (option) {
        return option.value === text;
      });
      if (dicItem) text = dicItem.text;
    }

    if (valueType) {
      if (valueType instanceof Array) {
        valueType.forEach(function (key) {
          var _unitTransform$key;

          text = unitTransform[key] ? (_unitTransform$key = unitTransform[key]) === null || _unitTransform$key === void 0 ? void 0 : _unitTransform$key.call(unitTransform, text, {
            errorResult: EmptyText
          }) : text;
        });
      } else {
        var _unitTransform$valueT;

        text = unitTransform[valueType] ? (_unitTransform$valueT = unitTransform[valueType]) === null || _unitTransform$valueT === void 0 ? void 0 : _unitTransform$valueT.call(unitTransform, text, {
          errorResult: EmptyText
        }) : text;
      }
    } else if (type === 'Date') {
      text = toTime(text, col.datePayload);
    }

    if (unit && !unitInTitle) {
      text = "".concat(text, " ").concat(unit);
    }

    if (dicItem) {
      if (dicItem.status || dicItem.color) {
        text = type === 'Tag' ? /*#__PURE__*/React.createElement(_Tag, {
          color: dicItem.status || dicItem.color
        }, text) : /*#__PURE__*/React.createElement(_Badge, {
          status: dicItem.status,
          color: dicItem.color,
          text: text
        });
        return text;
      }
    }

    if (ellipsisFn) text = ellipsisFn(text, col); // TODO： Highlighter 和 Paragraph 混合会导致 省略号异常
    // text =
    //   state.searchedColumn === col.key ? (
    //     <Highlighter
    //       highlightStyle={{ backgroundColor: '#ffc069', padding: 0 }}
    //       searchWords={[state.searchText]}
    //       autoEscape
    //       textToHighlight={text ? text.toString() : ''}
    //     />
    //   ) : (
    //     text
    //   );

    return text;
  };

  var actionColumnProps = {
    title: '操作',
    key: '_action',
    dataIndex: '_action',
    fixed: 'right',
    width: noData ? ActionColWidth : undefined
  };

  var renderActionCol = function renderActionCol(_, record, index) {
    if (noData) return {
      props: {
        colSpan: 0
      }
    };
    var text = /*#__PURE__*/React.createElement(Action, Object.assign({
      prefixCls: prefixCls,
      record: record,
      actions: actions
    }, actionConfig, {
      queryDic: _objectSpread(_objectSpread({}, externalQueryDic), {}, {
        record: record
      }),
      actionRule: actionRule,
      onActionClick: onActionClick
    }));

    if (renderColumnEvent) {
      if (isFunction(renderColumnEvent)) {
        return renderColumnEvent({
          text: text,
          record: record,
          index: index,
          dataSource: dataSource
        }, actionColumnProps.key, actionColumnProps);
      }
    }

    return text;
  };

  var onReset = function onReset() {
    form.resetFields();
    onCleanFiltered();
  };

  var renderReSetButton = function renderReSetButton() {
    return /*#__PURE__*/React.createElement(Button, {
      type: "link",
      size: "small",
      style: {
        padding: 0
      },
      onClick: onReset
    }, "\u91CD\u7F6E\u7B5B\u9009");
  };

  var renderActionColumn = function renderActionColumn() {
    if (props.showFilter === false || filterIsEmpty) return actions.length ? /*#__PURE__*/React.createElement(Column, Object.assign({}, actionColumnProps, {
      render: renderActionCol
    })) : null;
    return /*#__PURE__*/React.createElement(ColumnGroup, Object.assign({}, actionColumnProps), /*#__PURE__*/React.createElement(Column, Object.assign({}, actionColumnProps, {
      title: renderReSetButton,
      render: renderActionCol,
      className: "".concat(prefixCls, "-search-right")
    })));
  }; // TODO 后面需要调整渲染调用频率


  var render = function render() {
    var tmpColumns = _toConsumableArray(columns);

    var existSummary = tmpColumns.find(function (column) {
      return !!column.summary;
    });

    if (existSummary) {
      tmpColumns[0].fixed = true;
    }

    return /*#__PURE__*/React.createElement(React.Fragment, null, tmpColumns.map(renderColumn), !hideAllFilter && renderActionColumn());
  };

  var renderSummary = useMemoDeep(function () {
    var _columns = _toArray(columns),
        first = _columns[0],
        restColumns = _columns.slice(1);

    devWarning(!(first === null || first === void 0 ? void 0 : first.summary), 'Table', '第一列不能设置为统计栏');
    var totalColumnMap = {};
    restColumns.filter(function (column) {
      return !!column.summary;
    }).forEach(function (column) {
      if (column.summary instanceof Array) {
        column.summary.forEach(function (t) {
          if (t === 'Total') {
            totalColumnMap[column.key] = {
              val: 0,
              column: column
            };
          }
        });
      } else {
        totalColumnMap[column.key] = {
          val: 0,
          column: column
        };
      }
    });
    if (Object.keys(totalColumnMap).length === 0) return undefined;
    if (noData) return undefined;
    return function (pageData) {
      Object.keys(totalColumnMap).forEach(function (key) {
        var column = totalColumnMap[key].column; // 重置 val， 防止重复累加

        totalColumnMap[key].val = 0;
        pageData.forEach(function (record) {
          var text = getPathValue(record, column.dataIndex || column.key);
          if (isEmpty(text)) return;
          totalColumnMap[key].val = calc("".concat(totalColumnMap[key].val, " + ").concat(text, " "), EmptyText);
        });
      });
      return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Table.Summary.Row, null, /*#__PURE__*/React.createElement(Table.Summary.Cell, {
        index: 0
      }, "\u603B\u8BA1"), restColumns.map(function (column, index) {
        return /*#__PURE__*/React.createElement(Table.Summary.Cell, {
          index: index + 1,
          key: index + 1
        }, isEmpty(totalColumnMap[column.key]) ? null : columnTextRender(totalColumnMap[column.key].val, column, columnEllipsisRender));
      }), actions.length !== 0 && /*#__PURE__*/React.createElement(Table.Summary.Cell, {
        index: restColumns.length + 1
      })));
    }; // TODO： 需要注意 columnTextRender 方法所引入的变量。
  }, [columns]);
  return /*#__PURE__*/React.createElement(_Form, {
    form: form,
    style: {
      height: '100%'
    },
    autoComplete: "off",
    onValuesChange: onValuesChange
  }, /*#__PURE__*/React.createElement("div", {
    ref: tableRef,
    className: classnames("".concat(prefixCls, "-wrapper"), size && "".concat(prefixCls, "-").concat(size, "-wrapper"), _defineProperty({}, "".concat(prefixCls, "-wrapper-has-filter"), !filterIsEmpty))
  }, /*#__PURE__*/React.createElement(Table, Object.assign({
    prefixCls: "".concat(pCls, "-inline-table"),
    className: classnames(prefixCls, className),
    summary: renderSummary,
    tableLayout: "auto",
    // TODO 通过在空数据下添加长度为1的数组消除表头异常
    // TODO 自定义空数据会出现改问题：ID1001322。
    // dataSource={noData ? [{ id: '0' }] : dataSource}
    dataSource: dataSource,
    rowSelection: noData ? undefined : rowSelection
  }, tableProps, {
    expandable: noData ? undefined : tableProps.expandable,
    rowKey: rowKeyFn,
    size: "small"
  }), render())));
});
InlineTable.defaultProps = {
  prefixCls: 'pxx',
  rowKey: 'id',
  columns: [],
  dataSource: [],
  onChange: function onChange() {}
};
export default InlineTable;