import type { CellCls } from 'element-plus'

type DateType = 'date' | 'dateTime' | 'week' | 'month' | 'quarter' | 'year' | 'time'
type DateRangeType = 'dateRange' | 'dateTimeRange' | 'weekRange' | 'monthRange' | 'yearRange' | 'timeRange'

export type otherType = 'text' | 'button' | 'slot' | 'radio' | 'checkbox' | 'switch' | 'slot'

export type FormType =
  | 'input'
  | 'textarea'
  | 'password'
  | 'select'
  | 'treeSelect'
  | 'cascader'
  | 'colorPicker'
  | 'inputNumber'
  | 'inputDialogSelect'
  | DateType
  | DateRangeType
  | otherType
  | 'autocomplete'

export type ListConfig = {
  
  mode?: FormType | ((row: any, column: any, index: number) => FormType)

  
  label?: string

  
  prop?: string

  
  required?: boolean

  
  clearable?: boolean

  
  disabled?: boolean | ((row: any, column: any, index: number) => boolean)

  
  isView?: boolean | ((row: any, column: any, index: number) => boolean)

  
  placeholder?: string | ((row: any, column: any, index: number) => string)

  
  tabindex?: string

  
  options?: any[] | ((row: any) => any[])
  
  optionsValueKey?: string
  
  optionsLabelKey?: string

  
  trigger?: 'change' | 'blur' | 'save'

  
  rules: any[] | ((row: any) => any[])

  
  error?: boolean | ((row: any, index: number) => boolean)
  
  errorMessage?: string | ((row: any, index: number) => string)

  
  click?: (val: any, row: any, column: any, index: number) => void

  
  input?: (val: any, row: any, column: any, index: number) => void

  
  change?: (val: any, row: any, column: any, index: number, options?: any) => void

  
  blur?: (val: any, row: any, column: any, index: number) => void

  
  focus?: (val: any, row: any, column: any, index: number) => void

  
  keyupEnter?: (val: any, row: any, column: any, index: number) => void

  
  getRef?: (el: any) => void

  
  borderType?: any

  
  itemProps?: Record<any, any> | ((row: any, column: any, index: number) => Record<any, any>)

  
  inputWidth?: string

  

  
  btnName?: string

  

  
  keywordProp?: string

  
  pathProp?: string

  
  load?: (data: any, level: number) => Promise<any>

  
  search?: (text: string) => Promise<any>

  
  parentLinkChildrenStrictly?: boolean

  
  getGrandChildren?: (data?: any) => Promise<any>

  

  

  openDialog?: (row: any, column: any, index: number) => void

  

  

  select?: (val: any, row: any, column: any, index: number, option?: Record<any, any>) => void

  

  

  
  cascaderNameProp?: string
}

export interface Props {
  
  isView?: boolean

  
  config?: ListConfig[]

  
  data?: any[]

  
  rowKey?: string

  
  uuidKey?: string

  
  props?: {
    
    isView?: string

    
    isDisabled?: string
  }

  
  cellClassName?: CellCls

  
  selectionRows?: any[]

  
  trigger?: 'change' | 'blur' | 'save'
}

export interface Emits {
  
  (e: 'addRow'): void

  
  (e: 'removeRow'): void

  
  (e: 'sortEnd', oldData: any[], newData: any[], oldIndex: number, newIndex: number): void

  (e: 'update:selection-rows', selectionRows: any[]): void
}

export interface Slots {
  
  'pagination-left': {}

  
  tableLeft: {}

  
  tableRight: {}
}

export type Exposes = {
  
  getResultData: () => any[]

  
  recover: () => void

  
  recoverByKey: (key: string | string[] | number | number[]) => void

  
  insert: (newRow: any, index?: number, position?: 'before' | 'after') => void

  
  changeRowValueByKey: (rowValue: Record<'id' | 'value' | 'prop', any>) => void

  
  removeRowByKey: (id: any) => void

  
  deactivateAll: () => void

  
  validateAll: (callback?: (valid: boolean, errFiedList: any[]) => void) => void

  
  validateByRowKey: (key: string | string[] | number | number[], callback?: (result: any) => void) => void

  
  removeErrorByRowKey: (key: string | string[]) => void

  
  clearValidate: () => void

  
  changeRules: (key: string, callback?: (rule: any, checkFn: any) => void) => void

  
  removeCellError: (row: any, prop: string) => void
}
