// @ts-ignore: 忽略
import type { FormSchemaGetter } from '#/adapter/form';
// @ts-ignore: 忽略
import type { VxeGridProps } from '#/adapter/vxe-table';

import { DictEnum } from '@vben/constants';

// @ts-ignore: 忽略
import { getMultipleImageUploadConfig } from '#/components/upload';
import { getDictOptions } from '#/utils/dict';

export const reportFormSchema: any | FormSchemaGetter = () => [
  {
    component: 'Select',
    fieldName: 'drillEvaluation',
    label: '演练评估',
    componentProps: {
      placeholder: '请输入演练评估',
      options: getDictOptions(DictEnum.EXERCISE_EVALUATION),
    },
    rules: 'required',
  },
  {
    component: 'Input',
    fieldName: 'mainContent',
    label: '简述演练的主要内容',
    componentProps: {
      placeholder: '请输入演练的主要内容',
      type: 'textarea',
      rows: 3,
    },
    rules: 'required',
  },
  {
    component: 'Input',
    fieldName: 'existingProblems',
    label: '演练过程存在的问题',
    componentProps: {
      placeholder: '请输入演练过程存在的问题',
      type: 'textarea',
      rows: 3,
    },
    rules: 'required',
  },
  {
    component: 'Input',
    fieldName: 'improvementMeasures',
    label: '针对问题的改进措施',
    componentProps: {
      placeholder: '请输入针对问题的改进措施',
      type: 'textarea',
      rows: 3,
    },
    rules: 'required',
  },

  {
    component: 'Input',
    fieldName: 'managerComment',
    label: '经理点评',
    componentProps: {
      placeholder: '请输入经理点评',
      type: 'textarea',
      rows: 3,
    },
    rules: 'required',
  },
  {
    component: 'Input',
    fieldName: 'images',
    label: '图片',
    componentProps: {
      maxlength: 30,
    },
    dependencies: {
      show: () => false,
      triggerFields: [''],
    },
  },
  {
    component: 'Upload',
    fieldName: 'imagesPaths',
    label: '图片',
    componentProps: (row: any) => {
      return {
        ...getMultipleImageUploadConfig(5),
        multiple: true,
        onSuccess: (res: any, uploadFile: any, uploadFiles: any) => {
          if (res.code === 200) {
            const paths: string[] = [];
            uploadFiles.forEach((item: any) => {
              if (item.response?.code === 200) {
                paths.push(item.response.data.fileName);
              }
            });
            row.images = paths.join(',');

            return res.data;
          }
        },
      };
    },
    renderComponentContent: () => {
      return {
        default: () => '点击上传',
      };
    },
    rules: 'required',
  },
];

export const drawerFormSchema: any | FormSchemaGetter = () => [
  // {
  //   component: 'SectionTitle',
  //   fieldName: '_section_title',
  //   hideLabel: true,
  //   componentProps: {
  //     title: '基本信息',
  //   },
  // },
  {
    component: 'Input',
    fieldName: 'drillName',
    label: '应急演练名称',
    componentProps: {
      placeholder: '请输入应急演练名称',
    },
    rules: 'required',
  },
  {
    component: 'DatePicker',
    fieldName: 'drillTime',
    label: '演练时间',
    componentProps: {
      type: 'datetime',
      placeholder: '请选择演练时间',
      valueFormat: 'YYYY-MM-DD HH:mm:ss',
    },
    rules: 'required',
  },
  {
    component: 'Input',
    fieldName: 'organizationDepartment',
    label: '组织部门',
    componentProps: {
      placeholder: '请输入组织部门',
    },
    rules: 'required',
  },
  {
    component: 'InputNumber',
    fieldName: 'participantsCount',
    label: '参加人数',
    componentProps: {
      placeholder: '请输入参加人数',
      min: 0,
      step: 1,
    },
    rules: 'required',
  },
  {
    component: 'InputNumber',
    fieldName: 'totalCount',
    label: '总人数',
    componentProps: {
      placeholder: '请输入总人数',
      min: 0,
      step: 1,
    },
    rules: 'required',
  },
  {
    component: 'Input',
    fieldName: 'drillLocation',
    label: '演练地点/装置',
    componentProps: {
      placeholder: '请输入演练地点/装置',
    },
    rules: 'required',
  },
  {
    component: 'Input',
    fieldName: 'drillPurpose',
    label: '演练目的',
    componentProps: {
      placeholder: '请输入演练目的',
      type: 'textarea',
      rows: 3,
    },
    rules: 'required',
  },
  {
    component: 'Input',
    fieldName: 'accidentAssumption',
    label: '事件/事故现场假定',
    componentProps: {
      placeholder: '请输入事件/事故现场假定',
      type: 'textarea',
      rows: 3,
    },
    rules: 'required',
  },
  {
    component: 'Input',
    fieldName: 'drillPlanSummary',
    label: '演练方案简述',
    componentProps: {
      placeholder: '请输入演练方案简述',
      type: 'textarea',
      rows: 3,
    },
    rules: 'required',
  },
  {
    component: 'Input',
    fieldName: 'materialPreparation',
    label: '物资准备',
    componentProps: {
      placeholder: '请输入物资准备',
      type: 'textarea',
      rows: 3,
    },
    rules: 'required',
  },
  {
    component: 'Input',
    fieldName: 'precautions',
    label: '演练注意事项及要求',
    componentProps: {
      placeholder: '请输入演练注意事项及要求',
      type: 'textarea',
      rows: 3,
    },
    rules: 'required',
  },
];

export const defautTableColumns: VxeGridProps['columns'] = [
  {
    field: 'employeeName',
    title: '员工姓名',
    width: 100,
    fixed: 'left',
  },
];
