export interface SearchFormItem {
  field: string
  label: string
  type: 'input' | 'select' | 'date-range' | 'custom'
  placeholder?: string
  width?: string
  options?: Array<{ label: string; value: any }>
  defaultValue?: any
  component?: any // 自定义组件
  props?: Record<string, any> // 组件属性
}

export interface SearchFormConfig {
  items: SearchFormItem[]
  showAdvanced?: boolean
  advancedItems?: SearchFormItem[]
  maxItemsPerRow?: number // 每行最大显示的items数量，默认4
  collapsed?: boolean // 是否默认折叠，默认false
  params?: object | null
}

export interface TableColumn {
  prop: string
  label: string
  width?: string | number
  minWidth?: string | number
  align?: 'left' | 'center' | 'right'
  fixed?: boolean | 'left' | 'right'
  showOverflowTooltip?: boolean
  formatter?: (row: any, column: any, cellValue: any) => string
  render?: (h: any, { row, column, $index }: any) => any
  dictType?: string // 字典类型
}

export interface ActionButton {
  label: string
  type?: 'primary' | 'success' | 'warning' | 'danger' | 'info'
  icon?: string
  link?: boolean
  handler: (row: any) => void
  show?: (row: any) => boolean // 是否显示的条件函数
}

export interface TableActionButton {
  label: string
  type?: 'primary' | 'success' | 'warning' | 'danger' | 'info'
  icon?: string
  plain?: boolean
  loading?: boolean | { value: boolean } // 支持响应式值
  disabled?: boolean | { value: boolean } // 支持响应式值
  handler?: () => void
  show?: () => boolean // 是否显示的条件函数
  permission?: string // 权限标识，用于 checkPermi
}

export interface TableConfig {
  columns: TableColumn[]
  actions?: ActionButton[]
  loading?: boolean
  data: any[]
  selection?: boolean
  index?: boolean
  actionsWidth?: string | number
  rowKey?: string // 行数据的 Key，用于树形表格
  treeProps?: { // 树形表格的配置
    children?: string
    hasChildren?: string
  }
  defaultExpandAll?: boolean // 是否默认展开所有树节点
  expandRowKeys?: any[] // 当前展开的行
}

export interface PaginationConfig {
  show?: boolean
  pageSize?: number
  layout?: string
}

export interface TableListConfig {
  gridCode?: string // 字段配置ID，用于动态加载搜索表单
  searchForm?: SearchFormConfig
  table: TableConfig
  actions?: TableActionButton[] // 表格操作按钮配置
  pagination?: PaginationConfig
  api: {
    getList: (params: any) => Promise<{ list: any[]; total: number }>
  }
  queryParams: Record<string, any>
  onSearch?: (params: any) => void
  onReset?: () => void
  onPaginationChange?: (page: number, pageSize: number) => void
  onSelectionChange?: (selection: any[]) => void
  // 设置区域功能配置
  settings?: {
    refresh?: boolean // 是否显示刷新按钮
    download?: boolean | ((data: any[]) => void) | { // 是否显示下载按钮，或传递下载方法
      showColumnSelector?: boolean // 是否显示列选择器，默认为true
    }
    print?: boolean // 是否显示打印按钮
    size?: boolean // 是否显示大小设置按钮
    columns?: boolean // 是否显示列设置按钮
    fullscreen?: boolean // 是否显示全屏按钮
  }
}
