"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports["default"] = void 0;
var _pagination = _interopRequireDefault(require("@alifd/next/lib/pagination"));
var _table = _interopRequireDefault(require("@alifd/next/lib/table"));
var _icon = _interopRequireDefault(require("@alifd/next/lib/icon"));
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
var React = _interopRequireWildcard(require("react"));
var _excluded = ["dataSource", "isFilter", "columns", "style", "rowkey", "totalPage", "pageSize", "tableType", "isPagination", "fixedHeader", "useVirtual", "rowExpandable", "ColumnGroup", "maxBodyHeight", "expandedRowRender", "cellPropsList"];
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 myTable = function myTable(_ref) {
  var dataSource = _ref.dataSource,
    isFilter = _ref.isFilter,
    columns = _ref.columns,
    style = _ref.style,
    rowkey = _ref.rowkey,
    totalPage = _ref.totalPage,
    pageSize = _ref.pageSize,
    tableType = _ref.tableType,
    isPagination = _ref.isPagination,
    fixedHeader = _ref.fixedHeader,
    useVirtual = _ref.useVirtual,
    rowExpandable = _ref.rowExpandable,
    ColumnGroup = _ref.ColumnGroup,
    maxBodyHeight = _ref.maxBodyHeight,
    expandedRowRender = _ref.expandedRowRender,
    cellPropsList = _ref.cellPropsList,
    otherProps = (0, _objectWithoutPropertiesLoose2["default"])(_ref, _excluded);
  var _style = style || {};
  var _otherProps = otherProps || {};
  _otherProps.style = _style;
  var _useState = (0, React.useState)(false),
    loading = _useState[0],
    setLoading = _useState[1];
  var _useState2 = (0, React.useState)(1),
    current = _useState2[0],
    setCurrent = _useState2[1];
  var _useState3 = (0, React.useState)([]),
    Columns = _useState3[0],
    setColumns = _useState3[1];
  var _useState4 = (0, React.useState)([]),
    data = _useState4[0],
    setData = _useState4[1];
  var _useState5 = (0, React.useState)(dataSource),
    dataS = _useState5[0],
    setDataS = _useState5[1];
  console.log(columns, 666993666);
  (0, React.useEffect)(function () {
    //判断过滤改变data数据
    // if(isFilter[0].isFilter&&isFilter?[0].func !==''&&isFilter[0].code !==''){
    //   let fun = eval('(false || ' + isFilter[0].code + ')');
    //   fun(dataSource)
    //   console.log([fun(dataSource)],'--------fun(datas)')
    //   setData([fun(dataSource)]);
    //   setDataS([fun(dataSource)])
    // }
    setCurrent(1);
  }, []);
  (0, React.useEffect)(function () {
    var ChangeColumns01 = [].concat(columns);
    var data = [];
    var list = [];
    if (ColumnGroup) {
      for (var i = 0; i < ColumnGroup.length; i++) {
        var Group = ColumnGroup[i];
        var a = {
          "title": Group === null || Group === void 0 ? void 0 : Group.title,
          "children": [],
          key: Group['start']
        };
        for (var j = Group['start']; j < Group['end'] + 1; j++) {
          a.children.push(ChangeColumns01[j]);
          list.push(j);
        }
        data.push(a);
      }
    }
    for (var _i = 0; _i < ChangeColumns01.length; _i++) {
      if (!list.includes(_i)) {
        ChangeColumns01[_i].key = _i;
        data.push(ChangeColumns01[_i]);
      }
    }
    data.sort(function (a, b) {
      return a.key - b.key;
    });
    var Data = [].concat(data);
    setColumns(data);
  }, [ColumnGroup]);
  var onResizeChange = function onResizeChange(dataIndex, value) {
    var columnItem = columns.find(function (vo) {
      return vo.dataIndex === dataIndex;
    });
    if (!columnItem) {
      console.warn("\u672A\u627E\u5230dataIndex=" + dataIndex + "\u7684columnItem");
      return;
    }
  };
  var onSort = function onSort(dataIndex, order) {
    var dataSource = !isPagination ? dataS : data.sort(function (a, b) {
      var result = a[dataIndex] - b[dataIndex];
      return order === 'asc' ? result > 0 ? 1 : -1 : result > 0 ? -1 : 1;
    });
    !isPagination ? setDataS([].concat(dataSource)) : setData([].concat(dataSource));
  };
  var onFilter = function onFilter(filterParams) {
    var D = dataSource;
    var ds = [].concat(D);
    Object.keys(filterParams).forEach(function (key) {
      var selectedKeys = filterParams[key].selectedKeys;
      if (selectedKeys.length) {
        ds = ds.filter(function (record) {
          return record['key'] === selectedKeys[0];
        });
      }
    });
    !isPagination ? setDataS([].concat(ds)) : setData([].concat(ds));
  };
  var extraProps = (0, _extends2["default"])({
    useVirtual: useVirtual,
    loading: loading,
    dataSource: !isPagination ? dataS : data,
    hasBorder: tableType === '边框线',
    primaryKey: rowkey,
    isZebra: tableType === '斑马纹',
    fixedHeader: fixedHeader,
    maxBodyHeight: maxBodyHeight,
    rowExpandable: rowExpandable,
    expandedRowRender: expandedRowRender,
    // cellProps:{cellProps}
    onResizeChange: {
      onResizeChange: onResizeChange
    },
    onSort: {
      onSort: onSort
    },
    onFilter: {
      onFilter: onFilter
    },
    sortIcons: {
      desc: /*#__PURE__*/React.createElement(_icon["default"], {
        style: {
          top: '6px',
          left: '4px'
        },
        type: 'arrow-down',
        size: "xxs"
      }),
      asc: /*#__PURE__*/React.createElement(_icon["default"], {
        style: {
          top: '-6px',
          left: '4px'
        },
        type: 'arrow-up',
        size: "xxs"
      })
    }
  }, otherProps);
  console.log(data, '---------extraProps');
  return /*#__PURE__*/React.createElement("div", {
    style: tableType == '边框线' ? {
      border: ' 1px solid RGB(240,240,240)',
      overflowY: 'auto'
    } : {
      overflowY: 'auto'
    }
  }, ColumnGroup ? /*#__PURE__*/React.createElement(_table["default"], extraProps, Columns.map(function (item) {
    return item.children ? /*#__PURE__*/React.createElement(_table["default"].ColumnGroup, {
      title: item.title
    }, item.children.map(function (i) {
      return /*#__PURE__*/React.createElement(_table["default"].Column, i);
    })) : /*#__PURE__*/React.createElement(_table["default"].Column, item);
  })) : /*#__PURE__*/React.createElement(_table["default"].StickyLock, (0, _extends2["default"])({
    columns: columns
  }, extraProps)), isPagination && !useVirtual ? /*#__PURE__*/React.createElement("div", {
    style: {
      display: 'flex',
      height: 80,
      alignItems: 'center',
      padding: 20,
      justifyContent: 'space-between'
    }
  }, /*#__PURE__*/React.createElement("div", {
    style: {
      color: ' #9c9fa3'
    }
  }, "\u5171 ", /*#__PURE__*/React.createElement("a", {
    style: {
      color: '#9c9fa3'
    }
  }, data === null || data === void 0 ? void 0 : data.length), " \u9879\u6570\u636E"), /*#__PURE__*/React.createElement(_pagination["default"], {
    defaultCurrent: 1,
    total: data === null || data === void 0 ? void 0 : data.length,
    onChange: function onChange(page) {
      setData([]);
      setCurrent(page);
    }
  })) : null);
};
myTable.displayName = 'myTable';
var _default = myTable;
exports["default"] = _default;