import { FormConfig } from '@/types/basic-form';

/** 隐患问题类别：1-规章制度类，2-建筑安全类 */
export const DANGER_TYPE_OPTIONS = [
  { label: '规章制度类', value: 1 },
  { label: '建筑安全类', value: 2 },
];

/** 问题主要原因：1-人的不安全行为，2-物的不安全状态，3-环境的不利影响，4-管理缺陷 */
export const REASON_OPTIONS = [
  { label: '人的不安全行为', value: 1 },
  { label: '物的不安全状态', value: 2 },
  { label: '环境的不利影响', value: 3 },
  { label: '管理缺陷', value: 4 },
];

/** 隐患台账新增/编辑表单配置（字段顺序：隐患问题类别、隐患问题、问题主要原因、任务来源、整改要求、整改日期、复查人员所属部门、复查人员、举一反三是否推送、举一反三内容、举一反三责任部门、举一反三时限） */
export const HIDDEN_DANGER_FORM_CONFIG: FormConfig[] = [
  {
    prop: 'typeId',
    label: '隐患问题类别：',
    component: 'ElSelect',
    componentProps: {
      placeholder: '请选择隐患问题类别',
      style: { width: '100%' },
    },
    selectOptions: DANGER_TYPE_OPTIONS,
  },
  {
    prop: 'dangerProblem',
    label: '隐患问题：',
    component: 'ElInput',
    componentProps: {
      placeholder: '请输入隐患问题描述',
    },
  },
  {
    prop: 'reasonId',
    label: '问题主要原因：',
    component: 'ElSelect',
    componentProps: {
      placeholder: '请选择问题主要原因',
      style: { width: '100%' },
    },
    selectOptions: REASON_OPTIONS,
  },
  {
    prop: 'taskSource',
    label: '任务来源：',
    component: 'ElInput',
    componentProps: {
      placeholder: '如：上级检查、院内自查',
    },
  },
  {
    prop: 'rectificationRequirement',
    label: '整改要求：',
    component: 'ElInput',
    componentProps: {
      placeholder: '请输入整改要求',
    },
  },
  {
    prop: 'rectificationDepartmentIds',
    label: '整改责任部门：',
    slot: 'rectificationDepartmentIds',
  }, 
  {
    prop: 'rectificationResponsibleIds',
    label: '整改负责人：',
    slot: 'rectificationResponsibleIds',
  },
  {
    prop: 'rectificationDeadline',
    label: '整改日期：',
    component: 'ElDatePicker',
    componentProps: {
      type: 'date',
      placeholder: '请选择整改日期',
      valueFormat: 'YYYY-MM-DD',
      style: { width: '100%' },
    },
  },
  {
    prop: 'reviewDepartmentId',
    label: '复查人员所属部门：',
    slot: 'reviewDepartmentId',
    componentProps: {
      placeholder: '请选择复查人员所属部门',
      style: { width: '100%' },
    },
  },
  {
    prop: 'reviewPersonId',
    label: '复查人员：',
    slot: 'reviewPerson',
    componentProps: {
      placeholder: '请选择复查人员',
      style: { width: '100%' },
    },
  },
  {
    prop: 'isDrawLessonsPush',
    label: '举一反三是否推送：',
    slot: 'isDrawLessonsPush',
  },
  {
    prop: 'drawLessonsContent',
    label: '',
    component: 'ElInput',
    componentProps: {
      placeholder: '如：上级检查、院内自查',
      style: { paddingLeft: '136.5px' },
    },
  },
  {
    prop: 'drawLessonsDepartmentIds',
    label: '举一反三责任部门：',
    slot: 'drawLessonsDepartmentIds',
  },
  {
    prop: 'drawLessonsDeadline',
    label: '举一反三时限：',
    slot: 'drawLessonsDeadline',
  },
];

/**
 * 整改详情完整表单配置：原有字段（只读）+ 整改完成情况、整改完成时间、附件
 * 直接用于整改隐患页的 BasicForm
 */
export const HIDDEN_DANGER_RECTIFY_FORM_CONFIG: FormConfig[] = [
  {
    prop: 'typeId',
    label: '隐患问题类别：',
    component: 'ElSelect',
    componentProps: {
      placeholder: '请选择隐患问题类别',
      style: { width: '100%' },
      disabled: true,
    },
    selectOptions: DANGER_TYPE_OPTIONS,
  },
  {
    prop: 'dangerProblem',
    label: '隐患问题：',
    component: 'ElInput',
    componentProps: {
      placeholder: '请输入隐患问题描述',
      disabled: true,
    },
  },
  {
    prop: 'reasonId',
    label: '问题主要原因：',
    component: 'ElSelect',
    componentProps: {
      placeholder: '请选择问题主要原因',
      style: { width: '100%' },
      disabled: true,
    },
    selectOptions: REASON_OPTIONS,
  },
  {
    prop: 'taskSource',
    label: '任务来源：',
    component: 'ElInput',
    componentProps: {
      placeholder: '如：上级检查、院内自查',
      disabled: true,
    },
  },
  {
    prop: 'rectificationRequirement',
    label: '整改要求：',
    component: 'ElInput',
    componentProps: {
      placeholder: '请输入整改要求',
      disabled: true,
    },
  },
  {
    prop: 'rectificationDeadline',
    label: '整改日期：',
    component: 'ElDatePicker',
    componentProps: {
      type: 'date',
      placeholder: '请选择整改日期',
      valueFormat: 'YYYY-MM-DD',
      style: { width: '100%' },
      disabled: true,
    },
  },
  {
    prop: 'reviewDepartmentId',
    label: '复查人员所属部门：',
    slot: 'reviewDepartmentId',
    componentProps: {
      placeholder: '请选择复查人员所属部门',
      style: { width: '100%' },
      disabled: true,
    },
  },
  {
    prop: 'reviewPersonId',
    label: '复查人员：',
    slot: 'reviewPerson',
    componentProps: {
      placeholder: '请选择复查人员',
      style: { width: '100%' },
      disabled: true,
    },
  },
  {
    prop: 'isDrawLessonsPush',
    label: '举一反三是否推送：',
    slot: 'isDrawLessonsPush',
    componentProps: { disabled: true },
  },
  //   {
  //     prop: 'drawLessonsContent',
  //     label: '举一反三内容：',
  //     component: 'ElInput',
  //     componentProps: {
  //       placeholder: '选填，推送举一反三时建议填写',
  //       disabled: true,
  //     },
  //   },
  //   {
  //     prop: 'drawLessonsDepartmentIds',
  //     label: '举一反三责任部门：',
  //     component: 'ElSelect',
  //     // slot: 'drawLessonsDepartmentIds',
  //     componentProps: {
  //       placeholder: '请选择举一反三责任部门，可多选',
  //       style: { width: '100%' },
  //       disabled: true,
  //     },
  //   },
  //   {
  //     prop: 'drawLessonsDeadline',
  //     label: '举一反三时限：',
  //     component: 'ElDatePicker',
  //     componentProps: {
  //       type: 'date',
  //       placeholder: '请选择举一反三时限',
  //       valueFormat: 'YYYY-MM-DD',
  //       style: { width: '100%' },
  //       disabled: true,
  //     },
  //   },
  // 整改详情额外字段（可编辑，填写后点「整改」提交）
  {
    prop: 'rectificationCompletionStatus',
    label: '整改完成情况：',
    component: 'ElInput',
    componentProps: {
      placeholder: '请输入整改完成情况',
    },
  },
  {
    prop: 'rectificationCompletionTime',
    label: '整改完成时间：',
    component: 'ElDatePicker',
    componentProps: {
      type: 'date',
      placeholder: '请选择整改完成时间',
      valueFormat: 'YYYY-MM-DD',
      style: { width: '100%' },
    },
  },
  {
    prop: 'attachments',
    label: '附件：',
    slot: 'attachments',
    componentProps: {
      placeholder: '上传附件文档',
    },
  },
];

/**
 * 复查详情完整表单配置：整改字段全部禁用 + 复查意见（可编辑，清空）
 * 从主列表「复查」进入，底部按钮为「审查通过」「审查不通过」
 * 说明：附件字段继续复用整改/新增时的 Upload 组件（通过插槽渲染），仅在复查详情中禁用交互
 */
export const HIDDEN_DANGER_REVIEW_FORM_CONFIG: FormConfig[] = [
  ...HIDDEN_DANGER_RECTIFY_FORM_CONFIG.map((item) => ({
    ...item,
    componentProps: { ...item.componentProps, disabled: true },
  })),
  {
    prop: 'reviewComments',
    label: '复查意见：',
    slot: 'reviewComments',
    componentProps: {
      placeholder: '请输入复查意见（选填），限300字',
    },
  },
];

export const HIDDEN_DANGER_FORM_DATA = {
  typeId: undefined as number | undefined,
  dangerProblem: '',
  reasonId: undefined as number | undefined,
  taskSource: '',
  rectificationRequirement: '',
  rectificationDeadline: '',
  reviewDepartmentId: undefined as number | undefined,
  reviewPersonId: undefined as number | undefined,
  reviewPersonName: '',
  isDrawLessonsPush: 0,
  drawLessonsContent: '',
  drawLessonsDepartmentIds: '',
  drawLessonsDeadline: '',
  // 提交接口需要，下发时再填
  rectificationDepartmentIds: '',
  rectificationResponsiblePerson: '',
  // 整改详情展示（接口可能返回）
  rectificationCompletionStatus: '',
  rectificationCompletionTime: '',
  attachments: '',
  reviewComments: '',
  rectificationResponsibleUserId: '',
};

export const HIDDEN_DANGER_FORM_RULES = {
  typeId: [{ required: true, message: '请选择隐患问题类别', trigger: 'change' }],
  dangerProblem: [{ required: true, message: '请输入隐患问题', trigger: 'blur' }],
  reasonId: [{ required: true, message: '请选择问题主要原因', trigger: 'change' }],
  taskSource: [{ required: true, message: '请输入任务来源', trigger: 'blur' }],
  rectificationRequirement: [{ required: true, message: '请输入整改要求', trigger: 'blur' }],
  rectificationDeadline: [{ required: true, message: '请选择整改日期', trigger: 'change' }],
  reviewDepartmentId: [{ required: true, message: '请选择复查人员所属部门', trigger: 'change' }],
  reviewPersonId: [{ required: true, message: '请选择复查人员', trigger: 'change' }],
  isDrawLessonsPush: [{ required: true, message: '请选择举一反三是否推送', trigger: 'change' }],
  drawLessonsContent: [
    {
      required: true,
      message: '请输入举一反三内容',
      trigger: 'blur',
    },
  ],
  drawLessonsDepartmentIds: [
    {
      required: true,
      message: '请选择举一反三责任部门',
      trigger: 'change',
    },
  ],
  drawLessonsDeadline: [
    {
      required: true,
      message: '请选择举一反三截止日期',
      trigger: 'change',
    },
  ],
  rectificationCompletionStatus:[
    { required: true, message: '请输入整改完成情况', trigger: 'blur' }
  ],
  rectificationCompletionTime: [
    { required: true, message: '请选择整改完成时间', trigger: 'change' }
  ],
  rectificationDepartmentIds: [
    { required: true, message: '请选择整改责任部门', trigger: 'change' }
  ],
  rectificationResponsibleIds: [
    { required: true, message: '请选择整改负责人', trigger: 'change' }
  ],
};
