import { EnumProps } from '@/components/ProTable/interface'
import type {
  FormItemProps,
  FormProps,
  InputProps,
  AutocompleteProps,
  CascaderProps,
  ColorPickerProps,
  DatePickerProps,
  DividerProps,
  InputNumberProps,
  RadioButtonProps,
  RadioGroupProps,
  RateProps,
  SwitchProps,
  TransferProps,
  UploadProps,
  SliderProps,
  CheckboxProps,
  CheckboxGroupProps,
  RadioProps,
  TimePickerDefaultProps,
  TableColumnCtx,
  TimeSelectProps
} from 'element-plus'
import { TreeProps } from 'element-plus/es/components/tree-v2/src/types.mjs'
// 使用 Partial 辅助类型将 FormItemProps 的所有属性变为可选
type OptionalFormItemProps = Partial<FormItemProps>
type OptionalFormProps = Partial<FormProps>

type FormFieldNamesProps = {
  label: string
  value: string
  disabled?: string
  children?: string
}

type FormRenderScope = {
  model: Record<string, any>
  data: ValueType
  enumData: Record<string, any>
}
declare global {
  type ValueType = string | number | boolean | any[]
  interface FormSetProps {
    prop: string
    fieldName: string
    value: ValueType
  }
  /**
   * EcoForm
   */
  namespace EcoForm {
    interface Form extends OptionalFormProps {
      gutter?: number
      fixWidth?: boolean
      width?: number | string
      hasFooter?: boolean // 是否显示底部操作按钮
      submitButtonText?: string
      resetButtonText?: string
      cancelButtonText?: string
    }
    type ElTagName =
      | 'input'
      | 'el-input'
      | 'checkbox'
      | 'checkbox-group'
      | 'select'
      | 'select-v2'
      | 'date-picker'
      | 'input-number'
      | 'select-icon'
      | 'tree-select'
      | 'cascader'
      | 'radio-group'
      | 'radio-button'
      | 'file-upload'
      | 'img-upload'
      | 'file-upload-s3'
      | 'img-upload-s3'
      | 'slot'
      | 'rate'
      | 'slider'
      | 'switch'
      | 'time-picker'
      | 'time-select'
      | 'transfer' // label不显示 使用插槽吧
      | 'icon'
    interface Item<T = any> extends OptionalFormItemProps {
      prop: string
      eTag?: ElTagName
      fixWidth?: boolean
      props?:
        | InputProps
        | InputNumberProps
        | TreeProps
        | CascaderProps
        | DatePickerProps
        | TimePickerDefaultProps
        | TimeSelectProps
        | SwitchProps
        | SliderProps
        | RadioProps
        | RadioGroupProps
        | RadioButtonProps
        | CheckboxProps
        | CheckboxGroupProps
        | AutocompleteProps
        | RateProps
        | ColorPickerProps
        | TransferProps
        | DividerProps
        | UploadProps
        | any
      tooltip?: string
      hidden?: boolean | ((model: T) => boolean)
      span?: number
      enum?: EnumProps[] | ((model: T, enumMap: Map<string, Record<string, any>>) => Promise<any>) | ComputedRef<EnumProps[]>
      useCacheEnum?: boolean
      subField?: string
      subEnum?: EnumProps[] | ((params?: any, enumData?: any) => Promise<any> | EnumProps[])
      order?: number
      defaultValue?: ValueType | ((model: T, enumMap: Map<string, Record<string, any>>) => ValueType | any) | ComputedRef<ValueType>
      fieldNames?: FormFieldNamesProps
      render?: (scope: FormRenderScope) => VNode
      renderUseProp?: string[]
      destroy?: boolean | ((model: T) => boolean)
      width?: string | number
      labelSize?: 'default' | 'small' | 'large'
      valueFormat?: 'default' | 'string' | 'number' | 'boolean'
      [key: string]: any
    }
  }
}
