"use strict";

function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.renderColumnParam = exports["default"] = exports.TableTabsPane = exports.TableTabs = exports.ExportBtn = void 0;
var _tslib = require("tslib");
var _icons = require("@ant-design/icons");
var _antd = require("antd");
var _zh_CN = _interopRequireDefault(require("antd/es/locale/zh_CN"));
var _react = _interopRequireWildcard(require("react"));
var _useSettings4 = _interopRequireDefault(require("../vm-hooks/useSettings"));
require("./style");
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; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
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 _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 _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 _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; }
var VMTable = function VMTable(props) {
  var _props$rowKey = props.rowKey,
    rowKey = _props$rowKey === void 0 ? 'id' : _props$rowKey,
    _props$isIndex = props.isIndex,
    isIndex = _props$isIndex === void 0 ? true : _props$isIndex,
    columns = props.columns,
    _props$pagination = props.pagination,
    pagination = _props$pagination === void 0 ? false : _props$pagination,
    _props$height = props.height,
    height = _props$height === void 0 ? 120 : _props$height,
    _props$dataSource = props.dataSource,
    dataSource = _props$dataSource === void 0 ? [] : _props$dataSource,
    ext = (0, _tslib.__rest)(props, ["rowKey", "isIndex", "columns", "pagination", "height", "dataSource"]);
  var newColumns = (0, _react.useMemo)(function () {
    var result = isIndex ? columns ? [{
      title: '序号',
      render: function render(_, __, index) {
        if (pagination && typeof (pagination === null || pagination === void 0 ? void 0 : pagination.current) === 'number' && typeof (pagination === null || pagination === void 0 ? void 0 : pagination.pageSize) === 'number') {
          return ((pagination === null || pagination === void 0 ? void 0 : pagination.current) - 1) * (pagination === null || pagination === void 0 ? void 0 : pagination.pageSize) + index + 1;
        } else {
          return index + 1;
        }
      },
      width: 50
    }].concat(_toConsumableArray(columns)) : undefined : columns;
    if (result) {
      var _iterator = _createForOfIteratorHelper(result),
        _step;
      try {
        for (_iterator.s(); !(_step = _iterator.n()).done;) {
          var col = _step.value;
          if (!col.width) col.width = 70;
        }
      } catch (err) {
        _iterator.e(err);
      } finally {
        _iterator.f();
      }
    }
    return result;
  }, [columns, pagination]);
  var _useSettings = (0, _useSettings4["default"])(),
    theme = _useSettings.theme;
  return /*#__PURE__*/_react["default"].createElement(_antd.ConfigProvider, {
    locale: _zh_CN["default"]
  }, /*#__PURE__*/_react["default"].createElement(_antd.Table, Object.assign({
    className: "vm-table ".concat(theme),
    rowKey: rowKey,
    size: "small",
    scroll: {
      y: height,
      scrollToFirstRowOnChange: true
    },
    columns: newColumns,
    pagination: pagination ? Object.assign({
      // showQuickJumper: true,
      size: 'default',
      showSizeChanger: false,
      //   hideOnSinglePage: true,
      showTotal: function showTotal(total) {
        return "\u5171".concat(total, "\u6761");
      }
    }, pagination) : false,
    dataSource: dataSource
  }, ext)));
};
var ExportBtn = function ExportBtn(props) {
  var _onClick = props.onClick,
    items = props.items;
  var _useSettings2 = (0, _useSettings4["default"])(),
    theme = _useSettings2.theme;
  var menu = /*#__PURE__*/_react["default"].createElement(_antd.Menu, {
    onClick: function onClick(menuItem) {
      return _onClick && _onClick(menuItem.key);
    },
    items: items || [{
      label: '导出选中行',
      key: 'select-rows'
    }, {
      label: '导出当前页',
      key: 'current-page'
    }, {
      label: '导出全部',
      key: 'all'
    }]
  });
  return /*#__PURE__*/_react["default"].createElement(_antd.Dropdown, {
    overlay: menu,
    trigger: ['click'],
    className: "vtx-export-btn ".concat(theme),
    overlayClassName: "vtx-export-dropdown ".concat(theme)
  }, /*#__PURE__*/_react["default"].createElement(_antd.Button, {
    type: "primary",
    style: {
      padding: '0 10px'
    }
  }, /*#__PURE__*/_react["default"].createElement(_icons.ExportOutlined, null), "\u5BFC\u51FA", /*#__PURE__*/_react["default"].createElement(_icons.DownOutlined, null)));
};
exports.ExportBtn = ExportBtn;
var renderColumnParam = function renderColumnParam(cols) {
  var colsParam = [];
  cols.forEach(function (item) {
    colsParam.push({
      title: item.title,
      field: item.dataIndex
    });
  });
  return JSON.stringify(colsParam);
};
exports.renderColumnParam = renderColumnParam;
var TabPane = _antd.Tabs.TabPane;
var TableTabs = function TableTabs(props) {
  var _useSettings3 = (0, _useSettings4["default"])(),
    theme = _useSettings3.theme;
  return /*#__PURE__*/_react["default"].createElement(_antd.Tabs, Object.assign({}, props, {
    className: "vtx-table-tabs ".concat(theme)
  }), props.children);
};
exports.TableTabs = TableTabs;
var TableTabsPane = function TableTabsPane(props) {
  return /*#__PURE__*/_react["default"].createElement(TabPane, Object.assign({}, props, {
    style: {
      display: 'none'
    }
  }));
};
exports.TableTabsPane = TableTabsPane;
var _default = VMTable;
exports["default"] = _default;
//# sourceMappingURL=index.js.map
