/**
 * 预防检查任务单表单配置
 */
import type { FormConfig } from '@/types/basic-form';
import type { TaskManagementRuleForm } from '../type';
import { validateFormTime } from '@/utils/validateFormTime';

// 通用表单配置
const BASIC_FORM_CONFIG = {
  TASK_NAME: {
    label: '任务名称：',
    prop: 'name',
    component: 'ElInput',
    componentProps: {
      placeholder: '请输入任务名称',
      maxlength: 200,
      showWordLimit: true,
    },
  },
  INSPECT_TYPE: {
    label: '检查类型：',
    prop: 'inspectType',
    slot: 'inspectType',
  },
  DUE_COMPLETE_TIME: {
    label: '应完成时间：',
    prop: 'dueCompleteTime',
    component: 'ElDatePicker',
    componentProps: {
      placeholder: '请选择应完成时间',
      type: 'datetime',
      format: 'YYYY-MM-DD HH:mm',
      dateFormat: 'MMM DD, YYYY',
      timeFormat: 'HH:mm',
      valueFormat: 'YYYY-MM-DD HH:mm',
    },
  },
  INSPECT_REQUIREMENT: {
    label: '检查要求：',
    prop: 'inspectRequirement',
    component: 'ElInput',
    componentProps: {
      type: 'textarea',
      rows: 5,
      placeholder: '请输入检查要求',
      maxlength: 500,
      showWordLimit: true,
    },
  },
  USER_GROUP_LIST: {
    label: '检查责任人：',
    prop: 'userGroupList',
    slot: 'userGroupList',
  },
  IS_PUSH: {
    label: '是否推送：',
    prop: 'isPush',
    slot: 'isPush',
  },
  CREATE_USER: {
    label: '创建人：',
    prop: 'realname',
    component: 'ElInput',
    componentProps: {
      disabled: true,
    },
  },
};
// 任务管理表单信息 创建
export const TASK_MANAGEMENT_FROM_CONFIG_CREATE: FormConfig[] = [
  BASIC_FORM_CONFIG.TASK_NAME,
  {
    label: '被检查（自查）所/部/中心：',
    prop: 'deptIdList',
    slot: 'deptName',
  },
  BASIC_FORM_CONFIG.INSPECT_TYPE,
  BASIC_FORM_CONFIG.DUE_COMPLETE_TIME,
  BASIC_FORM_CONFIG.INSPECT_REQUIREMENT,
  BASIC_FORM_CONFIG.USER_GROUP_LIST,
  BASIC_FORM_CONFIG.IS_PUSH,
  BASIC_FORM_CONFIG.CREATE_USER,
];

// 任务管理表单信息 编辑
export const TASK_MANAGEMENT_FROM_CONFIG_EDIT: FormConfig[] = [
  BASIC_FORM_CONFIG.TASK_NAME,
  {
    label: '被检查（自查）所/部/中心：',
    prop: 'deptName',
    component: 'ElInput',
    componentProps: {
      placeholder: '请输入被检查（自查）所/部/中心',
      disabled: true,
    },
  },
  BASIC_FORM_CONFIG.INSPECT_TYPE,
  BASIC_FORM_CONFIG.DUE_COMPLETE_TIME,
  BASIC_FORM_CONFIG.INSPECT_REQUIREMENT,
  BASIC_FORM_CONFIG.USER_GROUP_LIST,
  BASIC_FORM_CONFIG.IS_PUSH,
  BASIC_FORM_CONFIG.CREATE_USER,
];

// 任务管理表单数据
export const TASK_MANAGEMENT_FROM_DATA: TaskManagementRuleForm = {
  name: '',
  deptIdList: [],
  inspectType: null,
  dueCompleteTime: '',
  inspectRequirement: '',
  userGroupList: [],
  isPush: null,
  realname: '',
  templateId: null,
};

// 任务管理表单规则
export const TASK_MANAGEMENT_FROM_RULES = {
  name: [{ required: true, message: '请输入任务名称', trigger: 'blur' }],
  deptIdList: [{ required: true, message: '请选择被检查（自查）所/部/中心', trigger: 'change' }],
  inspectType: [{ required: true, message: '请选择检查类型', trigger: 'change' }],
  dueCompleteTime: [
    { required: true, message: '请选择应完成时间', trigger: 'change' },
    { validator: validateFormTime, trigger: 'change' },
  ],
  userGroupList: [{ required: true, message: '请选择检查责任人', trigger: 'change' }],
  isPush: [{ required: true, message: '请选择是否推送', trigger: 'change' }],
};
