import type { FormSchemaGetter } from '#/adapter/form';
import type { VxeGridProps } from '#/adapter/vxe-table';
import type { SelectProps } from '#/adapter/form';

// 模拟系统岗位数据
export const mockPositions = [
  { label: '巡检员', value: '巡检员' },
  { label: '安全员', value: '安全员' },
  { label: '财务人员', value: '财务人员' },
  { label: '市场专员', value: '市场专员' },
  { label: '人事专员', value: '人事专员' },
  { label: '培训师', value: '培训师' },
  { label: '合规专员', value: '合规专员' },
  { label: '审计员', value: '审计员' },
  { label: '便利店店员', value: '便利店店员' },
  { label: '运营经理', value: '运营经理' },
];

// 模拟任务负责人数据
export const mockResponsibles = [
  { label: '张三', value: '张三' },
  { label: '李四', value: '李四' },
  { label: '王五', value: '王五' },
  { label: '赵六', value: '赵六' },
  { label: '孙七', value: '孙七' },
  { label: '周八', value: '周八' },
];

// 模拟已创建任务数据
export const mockCreatedTasks = [
  { label: '日常巡检任务', value: '日常巡检任务' },
  { label: '安全培训任务', value: '安全培训任务' },
  { label: '财务报表提交', value: '财务报表提交' },
  { label: '市场调研任务', value: '市场调研任务' },
  { label: '人事档案更新', value: '人事档案更新' },
];

// 模拟标准指引数据
export const mockGuidelines = [
  { label: '日常巡检标准指引', value: '日常巡检标准指引' },
  { label: '安全操作手册', value: '安全操作手册' },
  { label: '财务报表填写规范', value: '财务报表填写规范' },
  { label: '市场调研流程', value: '市场调研流程' },
  { label: '人事管理规定', value: '人事管理规定' },
];

// 通用Select组件配置函数
const createSearchSelectConfig = (options: any[], placeholder: string) => ({
  allowClear: true,
  placeholder,
  showSearch: true,
  filterOption: (input: string, option: any) =>
    (option?.label || '').toLowerCase().includes(input.toLowerCase()),
  options,
});

// 通用RadioGroup组件配置函数
const createRadioConfig = (options: { label: string; value: string }[], defaultValue?: string) => ({
  options,
  defaultValue,
});

export const queryFormSchema: FormSchemaGetter = () => [
  {
    component: 'Input',
    fieldName: 'taskName',
    label: '任务名称',
    componentProps: {
      placeholder: '请输入任务名称',
    },
  },
  {
    component: 'Select',
    fieldName: 'taskType',
    label: '任务类型',
    componentProps: {
      allowClear: true,
      placeholder: '请选择任务类型',
      options: [
        { label: '运营', value: '运营' },
        { label: '安全', value: '安全' },
        { label: '数质量', value: '数质量' },
        { label: '市场', value: '市场' },
        { label: '人事', value: '人事' },
        { label: '培训', value: '培训' },
        { label: '合规', value: '合规' },
        { label: '财务', value: '财务' },
        { label: '审计', value: '审计' },
        { label: '便利店', value: '便利店' },
        { label: '其它', value: '其它' },
      ],
    },
  },
  {
    component: 'Select',
    fieldName: 'taskResponsible',
    label: '任务负责人',
    componentProps: createSearchSelectConfig(mockResponsibles, '请选择任务负责人'),
  },
  {
    component: 'Select',
    fieldName: 'executivePost',
    label: '执行岗位',
    componentProps: createSearchSelectConfig(mockPositions, '请选择执行岗位'),
  },
  {
    component: 'Select',
    fieldName: 'taskFrequency',
    label: '任务频率',
    componentProps: {
      allowClear: true,
      placeholder: '请选择任务频率',
      options: [
        { label: '每天一次', value: '每天一次' },
        { label: '每周一次', value: '每周一次' },
        { label: '每月一次', value: '每月一次' },
        { label: '每两月一次', value: '每两月一次' },
        { label: '每三月一次', value: '每三月一次' },
        { label: '每六月一次', value: '每六月一次' },
        { label: '每年一次', value: '每年一次' },
      ],
    },
  },
  {
    component: 'Select',
    fieldName: 'status',
    label: '状态',
    componentProps: {
      allowClear: true,
      placeholder: '请选择状态',
      options: [
        { label: '关闭', value: '关闭' },
        { label: '启用', value: '启用' },
      ],
    },
  },
  {
    component: 'Select',
    fieldName: 'taskLevel',
    label: '任务级别',
    componentProps: {
      allowClear: true,
      placeholder: '请选择任务级别',
      options: [
        { label: '低', value: '低' },
        { label: '中', value: '中' },
        { label: '高', value: '高' },
      ],
    },
  },
  {
    component: 'Select',
    fieldName: 'formType',
    label: '表单类型',
    componentProps: {
      allowClear: true,
      placeholder: '请选择表单类型',
      options: [
        { label: '确认任务', value: '确认任务' },
        { label: '拍照任务', value: '拍照任务' },
        { label: '检查任务', value: '检查任务' },
        { label: '表单任务', value: '表单任务' },
        { label: '上传附件任务', value: '上传附件任务' },
      ],
    },
  },
  {
    component: 'Select',
    fieldName: 'timedDistribution',
    label: '定时分发',
    componentProps: {
      allowClear: true,
      placeholder: '请选择定时分发',
      options: [
        { label: '否', value: '否' },
        { label: '是', value: '是' },
      ],
    },
  },
  {
    component: 'Select',
    fieldName: 'taskSource',
    label: '任务来源',
    componentProps: {
      allowClear: true,
      placeholder: '请选择任务来源',
      options: [
        { label: '默认', value: '默认' },
        { label: '新增', value: '新增' },
      ],
    },
  },
];

export const tableColumns: VxeGridProps['columns'] = [
  {
    type: 'checkbox',
    width: 80,
  },
  {
    field: 'taskName',
    title: '任务名称',
    minWidth: 150,
  },
  {
    field: 'taskType',
    title: '任务类型',
    minWidth: 120,
  },
  {
    field: 'formType',
    title: '表单类型',
    minWidth: 120,
  },
  {
    field: 'taskResponsible',
    title: '任务负责人',
    minWidth: 120,
  },
  {
    field: 'executivePost',
    title: '执行岗位',
    minWidth: 120,
  },
  {
    field: 'taskFrequency',
    title: '任务频率',
    minWidth: 120,
  },
  {
    field: 'status',
    title: '状态',
    minWidth: 100,
  },
  {
    field: 'timedDistribution',
    title: '定时分发',
    minWidth: 100,
  },
  {
    field: 'taskSource',
    title: '任务来源',
    minWidth: 100,
  },
  {
    field: 'operator',
    title: '操作人',
    minWidth: 120,
  },
  {
    field: 'operationTime',
    title: '操作时间',
    minWidth: 180,
  },
  {
    field: 'action',
    fixed: 'right',
    slots: { default: 'action' },
    title: '操作',
    width: 300,
  },
];

// 定义通用的是/否选项
const yesNoOptions = [
  { label: '是', value: '是' },
  { label: '否', value: '否' },
];

// 定义任务类型选项
const taskTypeOptions = [
  { label: '运营', value: '运营' },
  { label: '安全', value: '安全' },
  { label: '数质量', value: '数质量' },
  { label: '市场', value: '市场' },
  { label: '人事', value: '人事' },
  { label: '培训', value: '培训' },
  { label: '合规', value: '合规' },
  { label: '财务', value: '财务' },
  { label: '审计', value: '审计' },
  { label: '便利店', value: '便利店' },
];

// 定义表单类型选项
const formTypeOptions = [
  { label: '确认任务', value: '确认任务' },
  { label: '拍照任务', value: '拍照任务' },
  { label: '检查任务', value: '检查任务' },
  { label: '表单任务', value: '表单任务' },
  { label: '上传附件任务', value: '上传附件任务' },
];

export const drawerFormSchema: FormSchemaGetter = () => [
  {
    component: 'Input',
    dependencies: {
      show: () => false,
      triggerFields: [''],
    },
    fieldName: 'id',
  },
  {
    component: 'Select',
    fieldName: 'executivePost',
    label: '执行岗位',
    componentProps: createSearchSelectConfig(mockPositions, '请选择执行岗位'),
    rules: 'required',
  },
  {
    component: 'Input',
    fieldName: 'taskName',
    label: '任务名称',
    componentProps: {
      placeholder: '请输入任务名称',
      maxlength: 100,
    },
    rules: 'required',
  },
  {
    component: 'Select',
    fieldName: 'taskType',
    label: '任务类型',
    componentProps: {
      placeholder: '请选择任务类型',
      options: taskTypeOptions,
    },
    rules: 'required',
  },
  {
    component: 'Select',
    fieldName: 'taskResponsible',
    label: '任务负责人',
    componentProps: createSearchSelectConfig(mockResponsibles, '请选择任务负责人'),
  },
  {
    component: 'Select',
    fieldName: 'formType',
    label: '表单类型',
    componentProps: {
      placeholder: '请选择表单类型',
      options: formTypeOptions,
    },
    rules: 'required',
  },
  {
    component: 'RadioGroup',
    fieldName: 'canAuthorize',
    label: '可授权',
    componentProps: createRadioConfig(yesNoOptions, '是'),
    rules: 'required',
  },
  {
    component: 'RadioGroup',
    fieldName: 'needScore',
    label: '评分',
    componentProps: createRadioConfig(yesNoOptions, '是'),
    rules: 'required',
  },
  {
    component: 'RadioGroup',
    fieldName: 'mustDo',
    label: '必做',
    componentProps: createRadioConfig(yesNoOptions, '是'),
    rules: 'required',
  },
  {
    component: 'RadioGroup',
    fieldName: 'executiveMode',
    label: '执行方式',
    componentProps: createRadioConfig([
      { label: '人工', value: '人工' },
      { label: '自动', value: '自动' },
    ], '人工'),
  },
  {
    component: 'Select',
    fieldName: 'taskFrequency',
    label: '任务频率',
    componentProps: {
      placeholder: '请选择任务频率',
      options: [
        { label: '每天一次', value: '每天一次' },
        { label: '每周一次', value: '每周一次' },
        { label: '每月一次', value: '每月一次' },
        { label: '每两月一次', value: '每两月一次' },
        { label: '每三月一次', value: '每三月一次' },
        { label: '每六月一次', value: '每六月一次' },
        { label: '每年一次', value: '每年一次' },
      ],
      defaultValue: '每天一次',
    },
    rules: 'required',
  },
  {
    component: 'InputNumber',
    fieldName: 'startTime',
    label: '开始时间',
    componentProps: {
      placeholder: '请输入开始时间',
      min: 1,
      defaultValue: 1,
    },
    rules: 'required',
  },
  {
    component: 'InputNumber',
    fieldName: 'deadline',
    label: '截止日期',
    componentProps: {
      placeholder: '请输入截止日期',
      min: 1,
    },
    rules: 'required',
  },
  {
    component: 'InputNumber',
    fieldName: 'planTime',
    label: '计划时间',
    componentProps: {
      placeholder: '请输入计划时间',
      min: 1,
      defaultValue: 1,
    },
    rules: 'required',
  },
  {
    component: 'InputNumber',
    fieldName: 'invalidDays',
    label: '失效天数',
    componentProps: {
      placeholder: '请输入失效天数',
      min: 0,
    },
    rules: 'required',
  },
  {
    component: 'InputNumber',
    fieldName: 'intervalDays',
    label: '间隔天数',
    componentProps: {
      placeholder: '请输入间隔天数',
      min: 0,
    },
    rules: 'required',
  },
  {
    component: 'InputNumber',
    fieldName: 'warningTime',
    label: '预警时间',
    componentProps: {
      placeholder: '请输入预警时间',
      min: 0,
    },
  },
  {
    component: 'Select',
    fieldName: 'taskLevel',
    label: '任务级别',
    componentProps: {
      placeholder: '请选择任务级别',
      options: [
        { label: '低', value: '低' },
        { label: '中', value: '中' },
        { label: '高', value: '高' },
      ],
    },
  },
  {
    component: 'Select',
    fieldName: 'taskExclusion',
    label: '任务排斥',
    componentProps: {
      placeholder: '请选择任务排斥',
      showSearch: true,
      filterOption: (input, option) =>
        (option?.label || '').toLowerCase().includes(input.toLowerCase()),
      options: mockCreatedTasks,
    },
  },
  {
    component: 'Input',
    fieldName: 'taskIcon',
    label: '任务图标',
    componentProps: {
      placeholder: '请输入任务图标',
    },
    rules: 'required',
  },
  {
    component: 'Input',
    fieldName: 'taskDescription',
    label: '任务描述',
    componentProps: {
      placeholder: '请输入任务描述',
      rows: 10,
    },
    // 使用自定义插槽渲染Tinymce编辑器
    slot: 'taskDescription',
    rules: 'required',
  },
  {
    component: 'Select',
    fieldName: 'standardGuideline',
    label: '标准指引',
    componentProps: {
      placeholder: '请选择标准指引',
      showSearch: true,
      filterOption: (input, option) =>
        (option?.label || '').toLowerCase().includes(input.toLowerCase()),
      mode: 'multiple',
      options: mockGuidelines,
    },
  },
  {
    component: 'Upload',
    fieldName: 'attachment',
    label: '附件',
    // 注意：该组件的详细实现已在taskTemplate-drawer.vue中通过插槽自定义
    // 这里仅保留基本配置，实际渲染由插槽控制
    componentProps: {
      // 基础配置
      action: '#',
      multiple: true,
    },
  },
  {
    component: 'RadioGroup',
    fieldName: 'status',
    label: '任务状态',
    componentProps: {
      options: [
        { label: '启用', value: '启用' },
        { label: '关闭', value: '关闭' },
      ],
      defaultValue: '启用',
    },
    rules: 'required',
  },
  {
    component: 'RadioGroup',
    fieldName: 'timedDistribution',
    label: '定时分发',
    componentProps: {
      options: [
        { label: '是', value: '是' },
        { label: '否', value: '否' },
      ],
      defaultValue: '是',
    },
    rules: 'required',
  },
  {
    component: 'Select',
    fieldName: 'archiveList',
    label: '归档列表',
    componentProps: {
      placeholder: '请选择归档列表',
      showSearch: true,
      filterOption: (input, option) =>
        (option?.label || '').toLowerCase().includes(input.toLowerCase()),
      // 模拟归档列表数据
      options: [
        { label: '日常巡检归档', value: '日常巡检归档' },
        { label: '安全检查归档', value: '安全检查归档' },
        { label: '财务报表归档', value: '财务报表归档' },
        { label: '市场调研归档', value: '市场调研归档' },
        { label: '人事档案归档', value: '人事档案归档' },
      ],
    },
    rules: 'required',
  },
];

export const formActions = [
  { type: 'button', text: '查询', submit: true, buttonProps: { type: 'primary' } },
  { type: 'button', text: '重置', reset: true },
  { type: 'button', text: '导出', buttonProps: { type: 'primary', ghost: true } },
];


export const mockData = [
  {
    id: '1',
    taskName: '日常巡检任务',
    taskType: '运营',
    formType: '检查任务',
    taskResponsible: '张三',
    executivePost: '巡检员',
    taskFrequency: '每天一次',
    status: '启用',
    timedDistribution: '是',
    taskSource: '新增',
    operator: '系统管理员',
    operationTime: '2023-10-01 10:00:00',
    // 示例附件数据
    attachment: [
      {
        name: '设备巡检记录表.xlsx',
        url: '#',
        size: 204800,
        type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
        uid: '1622547135000_1',
        status: 'success',
      },
      {
        name: '巡检操作规范.pdf',
        url: '#',
        size: 153600,
        type: 'application/pdf',
        uid: '1622547135000_2',
        status: 'success',
      },
    ],
    taskDescription: '这是一个日常巡检任务，需要检查设备运行状态和环境安全。',
    archiveList: '日常巡检归档',
  },
  {
    id: '2',
    taskName: '安全培训任务',
    taskType: '安全',
    formType: '表单任务',
    taskResponsible: '李四',
    executivePost: '安全员',
    taskFrequency: '每月一次',
    status: '启用',
    timedDistribution: '是',
    taskSource: '新增',
    operator: '系统管理员',
    operationTime: '2023-10-02 14:30:00',
    // 示例附件数据
    attachment: [
      {
        name: '安全培训教材.pdf',
        url: '#',
        size: 307200,
        type: 'application/pdf',
        uid: '1622547135000_3',
        status: 'success',
      },
      {
        name: '培训签到表.xlsx',
        url: '#',
        size: 51200,
        type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
        uid: '1622547135000_4',
        status: 'success',
      },
    ],
    taskDescription: '这是一个安全培训任务，需要组织员工进行安全知识学习。',
    archiveList: '安全检查归档',
  },
  {
    id: '3',
    taskName: '财务报表提交',
    taskType: '财务',
    formType: '上传附件任务',
    taskResponsible: '王五',
    executivePost: '财务人员',
    taskFrequency: '每月一次',
    status: '启用',
    timedDistribution: '否',
    taskSource: '默认',
    operator: '系统管理员',
    operationTime: '2023-10-03 09:15:00',
    // 示例附件数据
    attachment: [
      {
        name: '财务报表模板.xlsx',
        url: '#',
        size: 102400,
        type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
        uid: '1622547135000_5',
        status: 'success',
      },
    ],
    taskDescription: '这是一个财务报表提交任务，需要按时提交月度财务报表。',
    archiveList: '财务报表归档',
  },
  {
    id: '4',
    taskName: '市场调研任务',
    taskType: '市场',
    formType: '表单任务',
    taskResponsible: '赵六',
    executivePost: '市场专员',
    taskFrequency: '每周一次',
    status: '启用',
    timedDistribution: '是',
    taskSource: '新增',
    operator: '系统管理员',
    operationTime: '2023-10-04 16:45:00',
  },
  {
    id: '5',
    taskName: '人事档案更新',
    taskType: '人事',
    formType: '确认任务',
    taskResponsible: '孙七',
    executivePost: '人事专员',
    taskFrequency: '每三月一次',
    status: '关闭',
    timedDistribution: '是',
    taskSource: '默认',
    operator: '系统管理员',
    operationTime: '2023-10-05 11:20:00',
  },
  {
    id: '6',
    taskName: '合规检查任务',
    taskType: '合规',
    formType: '检查任务',
    taskResponsible: '周八',
    executivePost: '合规专员',
    taskFrequency: '每六月一次',
    status: '启用',
    timedDistribution: '否',
    taskSource: '新增',
    operator: '系统管理员',
    operationTime: '2023-10-06 15:10:00',
  },
];

