/* eslint-disable @typescript-eslint/no-explicit-any */
import { BaseWidgetProps } from "@/widgetLibrary/interface"
import { ReactNode } from "react"
import { ButtonVariant } from "../ButtonWidget/interface"

export type UploadStatus = "init" | "uploading" | "done" | "error"
export type UploadItem = {
  uid: string
  status?: UploadStatus
  originFile?: File
  percent?: number
  response?: object
  url?: string
  name?: string
  children?: ReactNode
}
export interface ValidateMessageOldProps {
  pattern?: "Email" | "URL" | "Regex"
  regex?: string
  minLength?: number
  maxLength?: number
  required?: boolean
  customRule?: string
  hideValidationMessage?: boolean
}
export interface TooltipWrapperProps {
  children?: ReactNode
  tooltipText?: string
  tooltipDisabled?: boolean
}
export interface UploadProps {
  text?: string
  colorScheme?: string
  loading?: boolean
  variant?: ButtonVariant
  listType?: string
  defaultFileList?: UploadItem[]
  imagePreview?: boolean
  fileList?: UploadItem[]
  autoUpload?: boolean
  directory?: boolean
  accept?: string
  limit?: number | { maxCount: number; hideOnExceedLimit?: boolean }
  action?: string
  disabled?: boolean
  drag?: boolean
  multiple?: boolean
  tip?: string | React.ReactNode
  headers?: Record<string, string>
  data?: object | ((any: any) => object)
  name?: string | ((any: any) => string)
  progressProps?: Partial<any>
  showUploadList?: any
  customRequest?: any
  renderUploadItem?: (
    originNode: ReactNode,
    file: UploadItem,
    fileList: UploadItem[],
  ) => ReactNode
  renderUploadList?: any,
  onChange?: (fileList: UploadItem[], file: UploadItem) => void
  onRemove?: (
    file: UploadItem,
    fileList: UploadItem[],
  ) => boolean | Promise<any>
  onProgress?: (file: UploadItem, e?: ProgressEvent) => void
  onReupload?: (file: UploadItem) => void
  onExceedLimit?: (files: File[], fileList: UploadItem[]) => void
  onPreview?: (file: UploadItem) => void
  beforeUpload?: (file: File, filesList: File[]) => boolean | Promise<any>
  onDrop?: (e: React.DragEvent) => void
  onDragOver?: (e: React.DragEvent) => void
  onDragLeave?: (e: React.DragEvent) => void
}
export interface WrappedUploadProps
  extends Pick<
      UploadProps,
      | "disabled"
      | "onChange"
      | "onRemove"
      | "variant"
      | "loading"
      | "text"
      | "colorScheme"
      | "customRequest"
    >,
    BaseWidgetProps {
  type: "button" | "dropzone"
  buttonText?: string
  dropText?: string
  fileType?: string[]
  selectionType?: "single" | "multiple" | "directory"
  appendFiles?: boolean
  showFileList?: boolean
  parseValue?: boolean
  minFiles?: number
  maxFiles?: number
  maxSize?: number
  minSize?: number
  sizeType?: string
  fileList?: UploadItem[]
  getValidateMessage: (value: UploadItem[]) => string
  handleUpdateMultiExecutionResult: (
    updateSlice: {
      displayName: string
      value: Record<string, any>
    }[],
  ) => void
}

export interface UploadWidgetProps
  extends WrappedUploadProps,
    BaseWidgetProps,
    TooltipWrapperProps,
    Omit<ValidateMessageOldProps, "value"> {
  currentList?: UploadItem[]
  displayName: string
  validateMessage: string
  value?: string[]
  files?: {
    lastModified: number
    name: string
    size: number
    type: string
  }[]
}
