import _Table from "antd/es/table";
import _Button from "antd/es/button";
import _extends from "@babel/runtime/helpers/extends";
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/objectWithoutPropertiesLoose";
var _excluded = ["actionColumnProps", "actionColumnButtons", "dataSource", "columns", "rowSelection", "style", "rowkey", "totalPage", "pageSize", "tableType", "fixedHeader", "useVirtual", "rowExpandable", "maxBodyHeight", "expandedRowRender", "cellPropsList", "hanshuOnclick"];
/* eslint-disable @typescript-eslint/no-shadow */
import * as React from 'react';
var antTableReal = function antTableReal(_ref) {
  var actionColumnProps = _ref.actionColumnProps,
    actionColumnButtons = _ref.actionColumnButtons,
    dataSource = _ref.dataSource,
    columns = _ref.columns,
    rowSelection = _ref.rowSelection,
    style = _ref.style,
    rowkey = _ref.rowkey,
    totalPage = _ref.totalPage,
    pageSize = _ref.pageSize,
    tableType = _ref.tableType,
    fixedHeader = _ref.fixedHeader,
    useVirtual = _ref.useVirtual,
    rowExpandable = _ref.rowExpandable,
    maxBodyHeight = _ref.maxBodyHeight,
    expandedRowRender = _ref.expandedRowRender,
    cellPropsList = _ref.cellPropsList,
    hanshuOnclick = _ref.hanshuOnclick,
    otherProps = _objectWithoutPropertiesLoose(_ref, _excluded);
  var _style = style || {};
  var _otherProps = otherProps || {};
  _otherProps.style = _style;
  var _loop = function _loop() {
    var _element$filters;
    var element = columns[index];
    if (element.filters && ((_element$filters = element.filters) === null || _element$filters === void 0 ? void 0 : _element$filters.length) === 0) {
      element.filters = null;
    }
    if (element.sortable && element.sorter.length === 0) {
      element.sorter = function (a, b) {
        if (typeof a[element.dataIndex] === 'number') {
          return a[element.dataIndex] - b[element.dataIndex];
        } else {
          // (a, b) => a.violationTypeStr.slice(0, 1).charCodeAt(0) - b.violationTypeStr.slice(0, 1).charCodeAt(0)
          return a[element.dataIndex].slice(0, 1).charCodeAt(0) - b[element.dataIndex].slice(0, 1).charCodeAt(0);
        }
      };
    }
    if (element.sorter && element.sorter.length === 0) {
      element.sorter = null;
    }
    if (element.render && element.render.length === 0) {
      element.render = null;
    }
  };
  for (var index = 0; index < (columns === null || columns === void 0 ? void 0 : columns.length); index++) {
    _loop();
  }
  if (actionColumnButtons && actionColumnButtons.dataSource && actionColumnButtons.dataSource.length !== 0) {
    columns.push(_extends({}, actionColumnProps, {
      key: 'action',
      render: function render(_, record) {
        return /*#__PURE__*/React.createElement("div", null, actionColumnButtons.dataSource.map(function (item, index) {
          if (!actionColumnButtons.text) {
            return /*#__PURE__*/React.createElement(_Button, _extends({
              style: {
                margin: '0 4px 0 0'
              },
              key: index
            }, actionColumnButtons.dataSource[index], {
              onClick: function onClick() {
                return actionColumnButtons.dataSource[index].onClick ? actionColumnButtons.dataSource[index].onClick(record) : null;
              }
            }), item.children);
          } else {
            return /*#__PURE__*/React.createElement(_Button, _extends({
              style: {
                padding: '4px'
              },
              key: index
            }, actionColumnButtons.dataSource[index], {
              onClick: function onClick() {
                return actionColumnButtons.dataSource[index].onClick ? actionColumnButtons.dataSource[index].onClick(record) : null;
              },
              type: item.type == 'primary' ? "link" : "text"
            }), item.children);
          }
        }));
      }
    }));
  }
  return /*#__PURE__*/React.createElement(_Table, _extends({
    columns: columns,
    dataSource: dataSource,
    pagination: false
  }, _otherProps));
};
antTableReal.displayName = 'antTableReal';
export default antTableReal;