import type { SearchFormConfig } from '../types'
import { getIntDictOptions } from '@/utils/dict'
import { DICT_TYPE } from '@/utils/dict'

// 抄送我的流程 - 搜索表单配置
export const copySearchFormConfig: SearchFormConfig = {
  items: [
    {
      field: 'processInstanceName',
      label: '流程名称',
      type: 'input',
      placeholder: '请输入流程名称',
      width: '240px'
    },
    {
      field: 'createTime',
      label: '抄送时间',
      type: 'date-range',
      width: '240px'
    }
  ]
}

// 待办任务 - 搜索表单配置
export const todoSearchFormConfig: SearchFormConfig = {
  items: [
    {
      field: 'name',
      label: '任务名称',
      type: 'input',
      placeholder: '请输入任务名称',
      width: '240px'
    }
  ],
  showAdvanced: true,
  advancedItems: [] // 动态填充
}

// 已办任务 - 搜索表单配置
export const doneSearchFormConfig: SearchFormConfig = {
  items: [
    {
      field: 'name',
      label: '任务名称',
      type: 'input',
      placeholder: '请输入任务名称',
      width: '240px'
    }
  ],
  showAdvanced: true,
  advancedItems: [] // 动态填充
}

// 管理任务 - 搜索表单配置
export const managerSearchFormConfig: SearchFormConfig = {
  items: [
    {
      field: 'name',
      label: '任务名称',
      type: 'input',
      placeholder: '请输入任务名称',
      width: '240px'
    },
    {
      field: 'createTime',
      label: '创建时间',
      type: 'date-range',
      width: '240px'
    }
  ]
}

// 动态生成高级搜索配置
export const generateAdvancedSearchItems = (categoryList: any[], processDefinitionList: any[]) => {
  return [
    {
      field: 'processDefinitionKey',
      label: '所属流程',
      type: 'select',
      placeholder: '请选择流程定义',
      width: '390px',
      options: processDefinitionList.map((item: any) => ({
        label: item.name,
        value: item.key
      }))
    },
    {
      field: 'createTime',
      label: '发起时间',
      type: 'date-range',
      width: '240px'
    }
  ]
}

// 流程分类选择器配置
export const categorySelectConfig = (categoryList: any[]) => ({
  field: 'category',
  label: '流程分类',
  type: 'select' as const,
  placeholder: '请选择流程分类',
  width: '155px',
  options: categoryList.map((item: any) => ({
    label: item.name,
    value: item.code
  }))
})

// 流程状态选择器配置
export const statusSelectConfig = {
  field: 'status',
  label: '流程状态',
  type: 'select' as const,
  placeholder: '请选择流程状态',
  width: '155px',
  options: getIntDictOptions(DICT_TYPE.BPM_PROCESS_INSTANCE_STATUS).map((dict: any) => ({
    label: dict.label,
    value: dict.value
  }))
}