


export type VxeTableColumn = {
  field: string
  title?: string
  children?: TableColumn[]
} & Recordable

export type CellFormat = string | ((text: string, record: Recordable, index: number) => string | number) | Map<string | number, any>

export type TableSlotDefault = {
  row: Recordable
  column: TableColumn
  $index: number
} & Recordable

export interface Pagination {
  small?: boolean
  background?: boolean
  pageSize?: number
  defaultPageSize?: number
  total?: number
  pageCount?: number
  pagerCount?: number
  currentPage?: number
  defaultCurrentPage?: number
  layout?: string
  pageSizes?: number[]
  popperClass?: string
  prevText?: string
  nextText?: string
  disabled?: boolean
  hideOnSinglePage?: boolean
}

export interface ExpandedRowRenderRecord<T> extends TableCustomRecord<T> {
  indent?: number
  expanded?: boolean
}

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

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

export interface TableSetPropsType {
  field: string
  path: string
  value: any
}

export declare type SortOrder = 'ascending' | 'descending'

type Fn = (...arg: any) => any

export declare type CustomRenderFunction<T> = (record: RecordProps<T>) => VNodeChild | JSX.Element

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


// https://element-plus-docs.bklab.cn/zh-CN/component/table.html#%E5%9F%BA%E7%A1%80%E8%A1%A8%E6%A0%BC
export interface ColumnProps {
  type?: 'default' | 'selection' | 'index' | 'expand',
  index?: number | ((index: number) => number),
  label: string,
  columnKey?: string,
  prop: string,
  width?: string | number,
  minWidth?: string | number,

  reserveSelection?:boolean,
  sortable?: boolean | string,
  renderHeader?: CustomRenderFunction<T> | VNodeChild | JSX.Element,
  sortMethod?: <T = any>(a: T, b: T) => number,
  sortBy?: (row: any, index: number) => string | string | string[],
  sortOrders?: SortOrder[],
  
  resizable?: boolean,
  formatter?: (row: any) => VNode | string,
  customRender?: (row: any, column: any, cellValue: any, index: number) => VNode | string,
  showOverflowTooltip?: boolean,
  align?: 'left' | 'center' | 'right',
  headerAlign?: 'left' | 'center' | 'right',
  className?: string,
  labelClassName?: string,
  selectable?: (row: any, index: number) => boolean,
  fixed?: 'left' | 'right'
  children?: TableColumn[],

  // 帮助文档
  helpMessage?: string | string[],
  //默认不显示
  defaultHidden?: boolean,
  //格式化
  format?: CellFormat,
  // 权限编码控制是否显示
  auth?: RoleEnum | RoleEnum[] | string | string[]
  // 业务控制是否显示
  ifShow?: boolean | ((column: BasicColumn) => boolean)
}


export interface TableRowSelection<T = any> {

  //清空选择
  clearSelection?: () => void

  //返回选择行
  getSelectionRows?: () => any

  //切换某一行的选中状态
  toggleRowSelection?: (row: T, selected: boolean) => void

  //切换全选和全部不选
  toggleAllSelection?: () => void

  //设置单选的高亮
  setCurrentRow?: (row: T) => void

  //后端给定的选中的值
  selectedRowKeys?: string[] | number[]

  //后端选中值对应的字段key
  rowSelectKeys: string;

}

export interface FetchParams {
  searchInfo?: Recordable
  page?: number
  sortInfo?: Recordable
}


export interface TableSetting {
  redo?: boolean
  form?: boolean
  setting?: boolean
  fullScreen?: boolean
}

export interface GetColumnsParams {
  ignoreIndex?: boolean
  ignoreAction?: boolean
  sort?: boolean
}


export interface BasicTableProps<T = any> {
  //是否显示序号
  showIndexColumn:boolean,
  // 点击行选中
  clickToRowSelect?: boolean
  isTreeTable?: boolean
  // 自定义排序方法
  sortFn?: (sortInfo: SorterResult) => any
  //align 对齐方式
  align?: 'left' | 'center' | 'right',
  //表头对齐方式
  headerAlign?: 'left' | 'center' | 'right',  
  // 排序方法
  tableKey:string, //用于存放自定义列缓存的key标识
  filterFn?: (data: Partial<Recordable<string[]>>) => any
  // 取消表格的默认padding
  inset?: boolean
  // 显示表格设置
  showTableSetting?: boolean
  tableSetting?: TableSetting
  // 斑马纹
  stripe?: boolean
  rowKey?: string | ((record: Recordable) => string)

  currentRowKey?: boolean
  // 计算合计行的方法
  summaryFunc?: (...arg: any) => Recordable[]
  // 自定义合计表格内容
  summaryData?: Recordable[]
  // 是否显示自定义合计行
  showDescSummary?: boolean
  // 表格schema
  schema?: any[]
  //请求的额外参数
  searchInfo?: Recordable,
  // 接口请求对象
  api?: (...arg: any) => Promise<any>
  // 请求之前处理参数
  beforeFetch?: Fn
  // 自定义处理接口返回参数
  afterFetch?: Fn
  // 查询条件请求之前处理
  handleSearchInfoFn?: Fn
  // 请求接口配置
  fetchSetting?: Partial<FetchSetting>
  // 立即请求接口
  immediate?: boolean
  // 在开起搜索表单的时候，如果没有数据是否显示表格
  emptyDataIsShowTable?: boolean
  //数据刷新后是否保留选项，仅对  type=selection 的列有效， 请注意， 需指定 row-key 来让这个功能生效。
  reserveSelection?: boolean
  // 默认的排序参数
  defSort?: Recordable
  // 列配置
  columns: BasicColumn[]
  // 序号列配置
  indexColumnProps?: BasicColumn
  actionColumn?: BasicColumn
  // 文本超过宽度是否显示。。。
  ellipsis?: boolean



  // 在分页改变的时候清空选项
  clearSelectOnPageChange?: boolean
  //

  // 数据
  dataSource?: Recordable[]
  // 标题右侧提示
  titleHelpMessage?: string | string[]
  // 表格滚动最大高度
  maxHeight?: number
  // 是否显示边框
  bordered?: boolean
  // 分页配置
  pagination?: Pagination | boolean
  // loading加载
  loading?: boolean

  rowSelection?: TableRowSelection<T>

  /**
   * Indent size in pixels of tree data
   * @default 15
   * @type number
   */
  indentSize?: number



  /**
   * Row's className
   * @type Function
   */
  rowClassName?: (record: TableCustomRecord<T>, index: number) => string


  /**
   * Table title renderer
   * @type Function | ScopedSlot
   */
  title?: VNodeChild | JSX.Element | string | ((data: Recordable) => string)




  /**
   * `table-layout` attribute of table element
   * `fixed` when header/columns are fixed, or using `column.ellipsis`
   *
   * @see https://developer.mozilla.org/en-US/docs/Web/CSS/table-layout
   * @version 1.5.0
   */
  tableLayout?: 'auto' | 'fixed' | string




  /**
   * Callback executed when pagination, filters or sorter is changed
   * @param pagination
   * @param filters
   * @param sorter
   * @param currentDataSource
   */
  onChange?: (pagination: any, filters: any, sorter: any, extra: any) => void

}




export type DynamicProps<T> = {
  [P in keyof T]: Ref<T[P]> | T[P] | ComputedRef<T[P]>
}
