"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 _react = _interopRequireWildcard(require("react"));

var _icons = require("@ant-design/icons");

var _propTypes = _interopRequireDefault(require("prop-types"));

var _antd = require("antd");

var _useSettings4 = _interopRequireDefault(require("../vm-hooks/useSettings"));

var _zh_CN = _interopRequireDefault(require("antd/es/locale/zh_CN"));

require("./style");

var _excluded = ["columns", "pagination"];

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

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 _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); 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 = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : 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 _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; }

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

var VMTable = function VMTable(props) {
  var columns = props.columns,
      pagination = props.pagination,
      ext = _objectWithoutProperties(props, _excluded);

  var newColumns = (0, _react.useMemo)(function () {
    var result = columns ? [{
      title: '序号',
      render: function render(_, __, index) {
        return (pagination.current - 1) * pagination.pageSize + index + 1;
      },
      width: 50
    }].concat(_toConsumableArray(columns)) : undefined;

    var _iterator = _createForOfIteratorHelper(result),
        _step;

    try {
      for (_iterator.s(); !(_step = _iterator.n()).done;) {
        var col = _step.value;
        if (!col.width) col.width = 60;
      }
    } 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, _extends({
    className: "vtx-modal-table ".concat(theme),
    rowKey: "id",
    size: "small",
    scroll: {
      x: 1500,
      y: 400
    },
    columns: newColumns,
    pagination: _objectSpread({
      showQuickJumper: true,
      size: 'default'
    }, pagination)
  }, ext)));
};

VMTable.propTypes = {
  columns: _propTypes["default"].array,
  pagination: _propTypes["default"].object
};
/**
 * 表格导出按钮
 * @param props
 * @returns
 */

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(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;
ExportBtn.propTypes = {
  onClick: _propTypes["default"].func,
  items: _propTypes["default"].array
};

var renderColumnParam = function renderColumnParam(cols) {
  var colsParam = [];
  cols.map(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, _extends({}, props, {
    className: "vtx-table-tabs ".concat(theme)
  }), props.children);
};

exports.TableTabs = TableTabs;
TableTabs.propTypes = {
  children: _propTypes["default"].element
};

var TableTabsPane = function TableTabsPane(props) {
  return /*#__PURE__*/_react["default"].createElement(TabPane, props, props.children);
};

exports.TableTabsPane = TableTabsPane;
var _default = VMTable;
exports["default"] = _default;
//# sourceMappingURL=index.js.map
