import { App } from 'vue';
import Table from './Table';
import config from './config';
import { merge } from 'lodash-es';
import {
  tableProps,
  TableSummary,
  TableSummaryRow,
  TableSummaryCell,
  TableColumn,
  TableColumnGroup
} from 'ant-design-vue/es/table';
import { reshow as reshowColumns } from './components/tableColumnsOperate';

// fix：table 在 install 的时候有自动全局安装了 TableSummary 相关组件，这里也要做这样的处理

// install: function install(app) {
//   app.component(TableSummary.name, TableSummary);
//   app.component(TableSummaryCell.name, TableSummaryCell);
//   app.component(TableSummaryRow.name, TableSummaryRow);
//   app.component(_Table.default.name, _Table.default);
//   app.component(_Column.default.name, _Column.default);
//   app.component(_ColumnGroup.default.name, _ColumnGroup.default);
//   return app;
// }

export {
  tableProps,
  TableSummary,
  TableSummaryRow,
  TableSummaryCell,
  TableColumn,
  TableColumnGroup,
  reshowColumns
};

Table.install = (app: App, options: any = {}) => {
  // 覆盖默认配置
  merge(config.props, options.props);
  // 名称和 antd 的全局名称一致
  app.component(Table.name, Table);

  app.component(TableSummary.name, TableSummary);
  app.component(TableSummaryCell.name, TableSummaryCell);
  app.component(TableSummaryRow.name, TableSummaryRow);
  app.component(TableColumn.name, TableColumn);
  app.component(TableColumnGroup.name, TableColumnGroup);
};

export default Table;
