"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports["default"] = void 0;
var _table = _interopRequireDefault(require("antd/lib/table"));
var _button = _interopRequireDefault(require("antd/lib/button"));
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
var React = _interopRequireWildcard(require("react"));
var _excluded = ["actionColumnProps", "actionColumnButtons", "dataSource", "columns", "rowSelection", "style", "rowkey", "totalPage", "pageSize", "tableType", "fixedHeader", "useVirtual", "rowExpandable", "maxBodyHeight", "expandedRowRender", "cellPropsList", "hanshuOnclick"];
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
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 = (0, _objectWithoutPropertiesLoose2["default"])(_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((0, _extends2["default"])({}, 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["default"], (0, _extends2["default"])({
              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["default"], (0, _extends2["default"])({
              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["default"], (0, _extends2["default"])({
    columns: columns,
    dataSource: dataSource,
    pagination: false
  }, _otherProps));
};
antTableReal.displayName = 'antTableReal';
var _default = antTableReal;
exports["default"] = _default;