import type { ElIconType } from '@/common/element/element.ts'
import type {
  TableColumnCtx,
  TableProps,
} from 'element-plus'
import type { DefaultRow } from 'element-plus/es/components/table/src/table/defaults'
import type { FormProps } from 'element-plus/es/components/form/src/form'

export interface ToolType {
  icon?: ElIconType
  type?: 'text' | 'default' | 'primary' | 'success' | 'warning' | 'info' | 'danger'
  label?: string
  action: () => void
}

export interface TableActionType<T> {
  icon?: ElIconType
  type?: 'text' | 'default' | 'primary' | 'success' | 'warning' | 'info' | 'danger'
  label?: string | ((data: { row: T, column: TableColumnCtx, $index: number }) => string)
  tooltip?: string | ((data: { row: T, column: TableColumnCtx, $index: number }) => string)
  loading?: boolean
  textBtn?: boolean
  show?: (data: { row: T, column: TableColumnCtx, $index: number }) => boolean
  action: (data: { row: T, column: TableColumnCtx, $index: number }) => Promise<boolean> | void
  confirm?: {
    title: string | ((data: { row: T, column: TableColumnCtx, $index: number }) => string)
    width?: string
    confirmButtonText?: string
    cancelButtonText?: string
  }
}

export interface ActionColumnType<T> {
  width?: string
  tableActions: TableActionType<T>[]
}

export type TablePropsType<T extends DefaultRow, F extends object> = Omit<TableProps<T>, 'data' | 'headerRowClassName' | 'cellClassName' | 'context'> & {
  treeLoad?: (param: F, row: T, expanded: any, resolve?: (data: T[]) => void) => void
}
export type FormPropsType = Partial<FormProps>
