import type { ColumnProps } from 'ant-design-vue/lib/table/Column';
import { ComponentType } from './componentType';
import type { TableRowSelection as ITableRowSelection } from 'ant-design-vue/lib/table/interface';

export declare type SortOrder = 'ascend' | 'descend';

export type SizeType = 'default' | 'middle' | 'small' | 'large';

// @ts-ignore
export interface BasicColumn extends ColumnProps {
  //编辑表格
  edit?: boolean;
  editRow?: boolean;
  editable?: boolean;
  editComponent?: ComponentType;
  editComponentProps?: Recordable;
  editRule?: boolean | ((text: string, record: Recordable) => Promise<string>);
  editValueMap?: (value: any) => string;
  editCellRender?: Recordable;
  onEditRow?: () => void;
  // 权限编码控制是否显示
  auth?: string[];
  // 业务控制是否显示
  ifShow?: boolean | ((column: BasicColumn) => boolean);
}

export interface TableActionType {
  reload: (opt) => Promise<void>;
  emit?: any;
  getColumns: (opt?) => BasicColumn[];
  setColumns: (columns: BasicColumn[] | string[]) => void;
  redoHeight: () => void;
}

export interface BasicTableProps {
  title?: string;
  dataSource: Function;
  columns: any[];
  pagination: object;
  showPagination: boolean;
  actionColumn?: BasicColumn;
  canResize: boolean;
  resizeHeightOffset: number;
  loading?: boolean;
  sortFn?: (sortInfo: SorterResult) => any;
  filterFn?: (data: Partial<Recordable<string[]>>) => any;
  scroll?: Object;
  maxHeight?: number;
  showTableSetting?: boolean;
  tableSetting?: TableSetting;
  rowClassName?: Function;
}

export interface SorterResult {
  column: ColumnType;
  order: SortOrder;
  field: string;
  columnKey: string;
}

export interface TableRowSelection<T = any> extends ITableRowSelection {
  /**
   * Callback executed when selected rows change
   * @type Function
   */
  onChange?: (selectedRowKeys: string[] | number[], selectedRows: T[]) => any;

  /**
   * Callback executed when select/deselect one row
   * @type Function
   */
  onSelect?: (record: T, selected: boolean, selectedRows: Object[], nativeEvent: Event) => any;

  /**
   * Callback executed when select/deselect all rows
   * @type Function
   */
  onSelectAll?: (selected: boolean, selectedRows: T[], changeRows: T[]) => any;

  /**
   * Callback executed when row selection is inverted
   * @type Function
   */
  onSelectInvert?: (selectedRows: string[] | number[]) => any;

  /**
   * 3.0 新增
   */
  preserveSelectedRowKeys?: boolean;
  hideSelectAll?: boolean;
  checkStrictly?: boolean;
}

export interface TableCustomRecord<T> {
  record?: T;
  index?: number;
}

export interface TableSetting {
  width?: number;
  redo?: boolean;
  size?: boolean;
  setting?: boolean;
  fullscreen?: boolean;
  striped?: boolean;
}
