// 字段类型枚举
export enum FieldType {
  INPUT = 'input',
  NUMBER = 'number',
  DATE = 'date',
  DATE_RANGE = 'date-range',
  SELECT = 'select',
  MULTI_SELECT = 'multi-select',
  REMOTE_SELECT = 'remote-select',
  FILTER_SELECT = 'filter-select',
  TREE_SELECT = 'tree-select',
  TREE_MULTI_SELECT = 'tree-multi-select',
  TREE_REMOTE_SELECT = 'tree-remote-select',
  TREE_FILTER_SELECT = 'tree-filter-select',
  CASCADER = 'cascader',
  POPUP_SELECT = 'popup-select'
}

// 选择器选项类型
export interface SelectOption {
  label: string
  value: any
  disabled?: boolean
  children?: SelectOption[]
}

// 字段配置接口
export interface FieldConfig {
  prop: string
  label: string
  width?: number | string
  minWidth?: number | string
  align?: 'left' | 'center' | 'right'
  type: FieldType
  required?: boolean
  rules?: any[]
  placeholder?: string
  disabled?: boolean
  readonly?: boolean
  
  // 数字输入框相关
  precision?: number
  step?: number
  min?: number
  max?: number
  
  // 选择器相关
  options?: SelectOption[]
  optionLabel?: string
  optionValue?: string
  multiple?: boolean
  filterable?: boolean
  remote?: boolean
  remoteMethod?: (query: string) => Promise<SelectOption[]>
  remoteShowSelectAll?: boolean
  
  // 树形选择器相关
  nodeKey?: string
  props?: {
    label?: string
    children?: string
    disabled?: string
    isLeaf?: string
  }
  showCheckbox?: boolean
  checkStrictly?: boolean
  defaultExpandAll?: boolean
  lazy?: boolean
  load?: (node: any, resolve: (data: SelectOption[]) => void) => void
  
  // 级联选择器相关
  cascaderProps?: {
    expandTrigger?: 'click' | 'hover'
    multiple?: boolean
    checkStrictly?: boolean
    emitPath?: boolean
    lazy?: boolean
    lazyLoad?: (node: any, resolve: (data: SelectOption[]) => void) => void
    value?: string
    label?: string
    children?: string
    disabled?: string
    leaf?: string
  }
  separator?: string
  
  // 弹窗选择器相关
  popupSelect?: PopupSelectConfig
  
  // 日期选择器相关
  valueFormat?: string
  format?: string
  type?: 'date' | 'datetime' | 'time' | 'week' | 'month' | 'year'
  
  // 通用属性
  clearable?: boolean
  size?: 'large' | 'default' | 'small'
  
  // 自定义渲染
  render?: (row: any, column: FieldConfig, index: number) => any
}

// 表格配置接口
export interface EditTableConfig {
  fields: FieldConfig[]
  maxHeight?: number | string
  border?: boolean
  stripe?: boolean
  size?: 'large' | 'default' | 'small'
  showIndex?: boolean
  indexLabel?: string
  indexWidth?: number
  showAction?: boolean
  actionWidth?: number
  actionLabel?: string
  actionFixed?: 'left' | 'right' | boolean
  
  // 分页配置
  pagination?: {
    enabled?: boolean
    pageSize?: number
    showSizeChanger?: boolean
    pageSizeOptions?: number[]
    showQuickJumper?: boolean
    showTotal?: boolean
  }
  
  // 导入导出配置
  importExport?: {
    showImport?: boolean
    showExport?: boolean
    importButtonText?: string
    exportButtonText?: string
    templateFileName?: string
    acceptFileTypes?: string[]
  }
}

// 表单验证规则
export interface FormRules {
  [key: string]: any[]
}

// 表格行数据
export interface TableRow {
  [key: string]: any
}

// 事件参数
export interface ActionEventParams {
  index: number
  row: TableRow
  type: 'add' | 'delete' | 'edit' | 'copy'
}

// 导入导出相关类型
export interface ImportParams {
  file: File
  fileName: string
}

export interface ExportParams {
  data: TableRow[]
  fields: FieldConfig[]
}

// 弹窗选择器相关类型
export interface PopupSelectConfig {
  // 弹窗配置
  title?: string              // 弹窗标题
  width?: string              // 弹窗宽度
  height?: string             // 弹窗高度
  
  // 表格配置
  api: {                    // 数据接口
    getList: (params: any) => Promise<{ list: any[]; total: number }>
  }
  
  // 默认查询参数
  queryParams?: Record<string, any>  // 调用接口时传递的额外参数
  
  // 查询条件配置
  searchForm?: {
    items: Array<{
      field: string
      label: string
      type: 'input' | 'select' | 'date-range' | 'custom'
      placeholder?: string
      width?: string | number
      options?: Array<{ label: string; value: any }>
      defaultValue?: any
      component?: any
      props?: Record<string, any>
    }>
    maxItemsPerRow?: number
  }
  
  // 表格列配置
  columns: Array<{
    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
  }>
  
  // 选择配置
  multiple?: boolean          // 是否多选，默认 false
  selection?: {             // 选择器配置
    labelKey?: string        // label 取的 key，默认 'label'
    valueKey?: string        // value 取的 key，默认 'value'
  }
  
  // 字段映射配置 - 用于将选中数据的字段映射到当前行的其他字段
  fieldMapping?: {          // 字段映射配置
    [targetField: string]: string  // 目标字段名: 源数据字段名
  }
  
  // 分页配置
  pagination?: {
    pageSize?: number         // 每页条数，默认 10
    showSizeChanger?: boolean // 显示每页条数选择
    pageSizeOptions?: number[] // 可选每页条数
  }
}
