import type { ComponentPublicInstance, ExtractPropTypes, PropType } from 'vue'
import type { LoadingType } from '../wd-loading/types'
import type { ImageMode } from '../wd-img/types'
export interface ChooseFileOption {
  multiple: boolean
  sizeType?: UploadSizeType[]
  sourceType: UploadSourceType[]
  maxCount: number
  accept: UploadFileType
  /**
   * 是否压缩视频，当 accept 为 video 时生效。
   */
  compressed: boolean
  /**
   * 拍摄视频最长拍摄时间，当 accept 为 video | media 时生效，单位秒。
   */
  maxDuration: number
  /**
   * 使用前置或者后置相机，当 accept 为 video | media 时生效，可选值为：back｜front。
   */
  camera: UploadCameraType
}
export type UploadFileItem = {
  [key: string]: any
  uid: number
  thumb?: string
  name?: string
  status?: UploadStatusType
  size?: number
  url: string
  percent?: number
  response?: string | Record<string, any>
}
export interface ChooseFile {
  path: string
  size?: number
  name?: string
  type: 'image' | 'video' | 'file'
  duration?: number
  thumb?: string
}
export type UploadSourceType = 'album' | 'camera'
export type UploadSizeType = 'original' | 'compressed'
export type UploadFileType = 'image' | 'video' | 'media' | 'all' | 'file'
export type UploadCameraType = 'front' | 'back'
export type UploadStatusType = 'pending' | 'loading' | 'success' | 'fail'
export type UploadBeforePreviewOption = {
  index: number
  imgList: string[]
  resolve: (isPass: boolean) => void
}
export type UploadBeforePreview = (option: UploadBeforePreviewOption) => void
export type UploadOnPreviewFailOption = {
  index: number
  imgList: string[]
}
export type UploadOnPreviewFail = (option: UploadOnPreviewFailOption) => void
export type UploadBeforeRemoveOption = {
  file: UploadFileItem
  index: number
  fileList: UploadFileItem[]
  resolve: (isPass: boolean) => void
}
export type UploadBeforeRemove = (option: UploadBeforeRemoveOption) => void
export type UploadBeforeChooseOption = {
  fileList: UploadFileItem[]
  resolve: (isPass: boolean) => void
}
export type UploadBeforeChoose = (option: UploadBeforeChooseOption) => void
export type UploadBeforeUploadOption = {
  files: Record<string, any>[]
  fileList: UploadFileItem[]
  resolve: (isPass: boolean) => void
}
export type UploadBeforeUpload = (options: UploadBeforeUploadOption) => void
export type UploadFormData = Record<string, any>
export type UploadBuildFormDataOption = {
  file: UploadFileItem
  formData: UploadFormData
  resolve: (formData: Record<string, any>) => void
}
export type UploadBuildFormData = (options: UploadBuildFormDataOption) => void
export type UploadFile = Partial<UploadFileItem> & {
  url: string
}
export type UploadMethod = (
  uploadFile: UploadFileItem,
  formData: UploadFormData,
  options: {
    action: string
    header: Record<string, any>
    name: string
    fileName: string
    fileType: 'image' | 'video' | 'audio'
    statusCode: number
    onSuccess: (
      res: UniApp.UploadFileSuccessCallbackResult,
      file: UploadFileItem,
      formData: UploadFormData,
    ) => void
    onError: (
      res: UniApp.GeneralCallbackResult,
      file: UploadFileItem,
      formData: UploadFormData,
    ) => void
    onProgress: (res: UniApp.OnProgressUpdateResult, file: UploadFileItem) => void
  },
) => void
export declare const uploadProps: {
  /**
   * 上传的文件列表,例如:[{name:'food.jpg',url:'https://xxx.cdn.com/xxx.jpg'}]
   * 类型：array
   * 默认值：[]
   */
  fileList: {
    type: PropType<UploadFile[]>
    default: () => never[]
  }
  /**
   * 必选参数，上传的地址
   * 类型：string
   * 默认值：''
   */
  action: {
    type: PropType<string>
    default: string
  }
  /**
   * 设置上传的请求头部
   * 类型：object
   * 默认值：{}
   */
  header: {
    type: PropType<Record<string, any>>
    default: () => void
  }
  /**
   * 是否支持多选文件
   * 类型：boolean
   * 默认值：false
   */
  multiple: {
    type: BooleanConstructor
    default: boolean
  }
  /**
   * 是否禁用
   * 类型：boolean
   * 默认值：false
   */
  disabled: {
    type: BooleanConstructor
    default: boolean
  }
  /**
   * 最大允许上传个数
   * 类型：number
   * 默认值：无
   */
  limit: NumberConstructor
  /**
   * 限制上传个数的情况下，是否展示当前上传的个数
   * 类型：boolean
   * 默认值：true
   */
  showLimitNum: {
    type: BooleanConstructor
    default: boolean
  }
  /**
   * 文件大小限制，单位为byte
   * 类型：number
   * 默认值：Number.MAX_VALUE
   */
  maxSize: {
    type: NumberConstructor
    default: number
  }
  /**
   * 选择图片的来源，chooseImage接口详细参数，查看官方手册
   * 类型：array
   * 默认值：['album','camera']
   */
  sourceType: {
    type: PropType<UploadSourceType[]>
    default: () => string[]
  }
  /**
   * 所选的图片的尺寸，chooseImage接口详细参数，查看官方手册
   * 类型：array
   * 默认值：['original','compressed']
   */
  sizeType: {
    type: PropType<UploadSizeType[]>
    default: () => string[]
  }
  /**
   * 文件对应的key，开发者在服务端可以通过这个key获取文件的二进制内容，uploadFile接口详细参数，查看官方手册
   * 类型：string
   * 默认值：'file'
   */
  name: {
    type: PropType<string>
    default: string
  }
  /**
   * HTTP请求中其他额外的formdata，uploadFile接口详细参数，查看官方手册
   * 类型：object
   * 默认值：{}
   */
  formData: {
    type: PropType<UploadFormData>
    default: () => void
  }
  /**
   * 预览失败执行操作
   * 类型：function({index,imgList})
   * 默认值：-
   */
  onPreviewFail: PropType<UploadOnPreviewFail>
  /**
   * 上传文件之前的钩子，参数为上传的文件和文件列表，若返回false或者返回Promise且被reject，则停止上传。
   * 类型：function({files,fileList,resolve})
   * 默认值：-
   */
  beforeUpload: PropType<UploadBeforeUpload>
  /**
   * 选择图片之前的钩子，参数为文件列表，若返回false或者返回Promise且被reject，则停止上传。
   * 类型：function({fileList,resolve})
   * 默认值：-
   */
  beforeChoose: PropType<UploadBeforeChoose>
  /**
   * 删除文件之前的钩子，参数为要删除的文件和文件列表，若返回false或者返回Promise且被reject，则停止上传。
   * 类型：function({file,fileList,resolve})
   * 默认值：-
   */
  beforeRemove: PropType<UploadBeforeRemove>
  /**
   * 图片预览前的钩子，参数为预览的图片下标和图片列表，若返回false或者返回Promise且被reject，则停止上传。
   * 类型：function({index,imgList,resolve})
   * 默认值：-
   */
  beforePreview: PropType<UploadBeforePreview>
  /**
   * 构建上传formData的钩子，参数为上传的文件、待处理的formData，返回值为处理后的formData，若返回false或者返回Promise且被reject，则停止上传。
   * 类型：function({file,formData,resolve})
   * 默认值：-
   * 最低版本：0.1.61
   */
  buildFormData: PropType<UploadBuildFormData>
  /**
   * 加载中图标类型
   * 类型：string
   * 默认值：'ring'
   */
  loadingType: {
    type: PropType<LoadingType>
    default: LoadingType
  }
  /**
   * 加载中图标颜色
   * 类型：string
   * 默认值：'#ffffff'
   */
  loadingColor: {
    type: PropType<string>
    default: string
  }
  /**
   * 文件类型，可选值：'image' | 'video' | 'media' | 'all' | 'file'
   * 默认值：image
   * 描述：'media'表示同时支持'image'和'video'，'file'表示支持除'image'和'video'外的所有文件类型，'all'标识支持全部类型文件
   * 'media'和'file'仅微信支持，'all'仅微信和H5支持
   */
  accept: {
    type: PropType<UploadFileType>
    default: UploadFileType
  }
  /**
   * file 数据结构中，status 对应的 key
   * 类型：string
   * 默认值：'status'
   */
  statusKey: {
    type: PropType<string>
    default: string
  }
  /**
   * 加载中图标尺寸
   * 类型：string
   * 默认值：'24px'
   */
  loadingSize: {
    type: PropType<string>
    default: string
  }
  /**
   * 是否压缩视频，当 accept 为 video 时生效。
   * 类型：boolean
   * 默认值：true
   */
  compressed: {
    type: BooleanConstructor
    default: boolean
  }
  /**
   * 拍摄视频最长拍摄时间，当 accept 为 video | media 时生效，单位秒。
   * 类型：number
   * 默认值：60
   */
  maxDuration: {
    type: NumberConstructor
    default: number
  }
  /**
   * 使用前置或者后置相机，当 accept 为 video | media 时生效，可选值为：back｜front。
   * 类型：UploadCameraType
   * 默认值：'back'
   */
  camera: {
    type: PropType<UploadCameraType>
    default: UploadCameraType
  }
  /**
   * 预览图片的mode属性
   */
  imageMode: {
    type: PropType<ImageMode>
    default: ImageMode
  }
  /**
   * 接口响应的成功状态（statusCode）值
   */
  successStatus: {
    type: NumberConstructor
    default: number
  }
  /**
   * 自定义上传按钮样式
   * 类型：string
   */
  customEvokeClass: {
    type: PropType<string>
    default: string
  }
  /**
   * 自定义预览图片列表样式
   * 类型：string
   */
  customPreviewClass: {
    type: PropType<string>
    default: string
  }
  /**
   * 是否选择文件后自动上传
   * 类型：boolean
   */
  autoUpload: {
    type: BooleanConstructor
    default: boolean
  }
  /**
   * 自定义上传文件的请求方法
   * 类型：UploadMethod
   * 默认值：-
   */
  uploadMethod: PropType<UploadMethod>
  customStyle: {
    type: PropType<string>
    default: string
  }
  customClass: {
    type: PropType<string>
    default: string
  }
}
export type UploadProps = ExtractPropTypes<typeof uploadProps>
export type UploadExpose = {
  /**
   * 手动触发上传
   */
  submit: () => void
}
export type UploadErrorEvent = {
  error: any
  file: UploadFileItem
  formData: UploadFormData
}
export type UploadChangeEvent = {
  fileList: UploadFileItem[]
}
export type UploadSuccessEvent = {
  file: UploadFileItem
  fileList: UploadFileItem[]
  formData: UploadFormData
}
export type UploadProgressEvent = {
  response: UniApp.OnProgressUpdateResult
  file: UploadFileItem
}
export type UploadOversizeEvent = {
  file: ChooseFile
}
export type UploadRemoveEvent = {
  file: UploadFileItem
}
export type UploadInstance = ComponentPublicInstance<UploadProps, UploadExpose>
