"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports["default"] = void 0;
exports.uuid = uuid;
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"));
require("./index.less");
var _excluded = ["actionColumnProps", "actionColumnButtons", "wholeStyle", "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,
    wholeStyle = _ref.wholeStyle,
    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 _useState = (0, React.useState)(''),
    ID = _useState[0],
    setID = _useState[1];
  (0, React.useEffect)(function () {
    setID("checkBox_" + uuid());
  }, []);
  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();
  }
  console.log(actionColumnButtons, 55555555555555555555);
  (0, React.useEffect)(function () {
    if (ID) {
      thead();
      tbody();
    }
  });
  var thead = function thead() {
    var _ref2;
    var elems = (_ref2 = document.getElementById(ID) || document) === null || _ref2 === void 0 ? void 0 : _ref2.querySelectorAll('.ant-table-thead')[0].querySelectorAll('tr')[0].querySelectorAll('th');
    var length = elems.length;
    for (var _index = 0; _index < length; _index++) {
      if (wholeStyle.tableHeader.ifborder) {
        elems[_index].style.borderTop = "1px solid  " + wholeStyle.tableHeader.borderColor;
        if (_index == 0) {
          elems[_index].style.borderLeft = "1px solid  " + wholeStyle.tableHeader.borderColor;
        }
        if (_index == length - 1) {
          elems[_index].style.borderRight = "1px solid  " + wholeStyle.tableHeader.borderColor;
        }
      }
      elems[_index].style.fontSize = wholeStyle.tableHeader.size + 'px'; // 字体大小
      elems[_index].style.fontWeight = wholeStyle.tableHeader.weight; //字体粗细
      elems[_index].style.color = wholeStyle.tableHeader.color; // 字体颜色
      elems[_index].style.borderColor = wholeStyle.tableHeader.borderColor; //边框颜色
      elems[_index].style.backgroundColor = wholeStyle.tableHeader.background; //背景色
      elems[_index].style.height = wholeStyle.tableHeader.height + 'px'; // 行高
      elems[_index].style.paddingLeft = wholeStyle.tableHeader.paddingLeft + 'px'; // 左边距
      elems[_index].style.paddingRight = wholeStyle.tableHeader.paddingRight + 'px'; // 右边距
      elems[_index].style.paddingTop = wholeStyle.tableHeader.paddingTop + 'px'; // 上边距
      elems[_index].style.paddingBottom = wholeStyle.tableHeader.paddingBottom + 'px'; // 下边距
    }
  };

  var tbody = function tbody() {
    var _ref3;
    var elems = (_ref3 = document.getElementById(ID) || document) === null || _ref3 === void 0 ? void 0 : _ref3.querySelectorAll('.ant-table-tbody')[0].querySelectorAll('tr');
    for (var _index2 = 0; _index2 < elems.length; _index2++) {
      var item = elems[_index2].querySelectorAll('td');
      for (var j = 0; j < item.length; j++) {
        if (wholeStyle.tableBody.ifborder) {
          if (j == 0) {
            item[j].style.borderLeft = "1px solid  " + wholeStyle.tableBody.borderColor;
          }
          if (j == item.length - 1) {
            item[j].style.borderRight = "1px solid  " + wholeStyle.tableBody.borderColor;
          }
        }
        item[j].style.fontSize = wholeStyle.tableBody.size + 'px'; // 字体大小
        item[j].style.fontWeight = wholeStyle.tableBody.weight; //字体粗细
        item[j].style.color = wholeStyle.tableBody.color; // 字体颜色
        item[j].style.borderColor = wholeStyle.tableBody.borderColor; //边框颜色
        item[j].style.backgroundColor = wholeStyle.tableBody.background; //背景色
        item[j].style.height = wholeStyle.tableBody.height + 'px'; // 行高
        item[j].style.paddingLeft = wholeStyle.tableBody.paddingLeft + 'px'; // 左边距
        item[j].style.paddingRight = wholeStyle.tableBody.paddingRight + 'px'; // 右边距
        item[j].style.paddingTop = wholeStyle.tableBody.paddingTop + 'px'; // 上边距
        item[j].style.paddingBottom = wholeStyle.tableBody.paddingBottom + 'px'; // 下边距
      }
    }
  };

  var tableProps = {
    bordered: wholeStyle.halvingLine ? wholeStyle.halvingLine : false
  };
  var nameDate = [];
  if (actionColumnButtons && actionColumnButtons.dataSource && actionColumnButtons.dataSource.length !== 0) {
    nameDate.push((0, _extends2["default"])({}, actionColumnProps, {
      key: 'action',
      render: function render(_, record) {
        return /*#__PURE__*/React.createElement("div", null, actionColumnButtons.dataSource.map(function (item, index) {
          if (item.verify) {
            if (record[item.verify]) {
              if (!actionColumnButtons.text) {
                return /*#__PURE__*/React.createElement(_button["default"], (0, _extends2["default"])({
                  size: actionColumnButtons.size,
                  style: {
                    margin: "0px " + item.margin + "px 0px  0px ",
                    color: item.color
                  },
                  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"])({
                  size: actionColumnButtons.size,
                  style: {
                    margin: "0px " + item.margin + "px 0px  0px",
                    padding: '0px',
                    color: item.color
                  },
                  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);
              }
            }
          } else {
            if (!actionColumnButtons.text) {
              return /*#__PURE__*/React.createElement(_button["default"], (0, _extends2["default"])({
                size: actionColumnButtons.size,
                style: {
                  margin: "0px " + item.margin + "px 0px  0px",
                  color: item.color
                },
                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"])({
                size: actionColumnButtons.size,
                style: {
                  margin: "0px " + item.margin + "px 0px  0px",
                  padding: '0px',
                  color: item.color
                },
                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("div", {
    id: ID
  }, /*#__PURE__*/React.createElement(_table["default"], (0, _extends2["default"])({
    className: "antTable"
  }, tableProps, {
    columns: columns.concat(nameDate),
    dataSource: dataSource,
    pagination: false
  }, _otherProps)));
};
antTableReal.displayName = 'antTableReal';
var _default = antTableReal;
exports["default"] = _default;
function uuid() {
  return (Math.random() * 1e6 >> 0).toString(36);
}