import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { useMineDepartmentStore } from '/@/store/modules/mine';

// 3. 生成动态表格列（接收动态状态映射）
export function getColumns(): BasicColumn[] {
  return [
    {
      title: '煤矿名称',
      dataIndex: 'mineName',
      width: 100,
    },
    {
      title: '图纸名称',
      dataIndex: 'fileName',
      width: 100,
    },
    {
      title: '图纸类型',
      dataIndex: 'fileType',
      width: 100,
    },
    {
      title: '更新时间',
      dataIndex: 'createTime',
      width: 100,
    },
    {
      title: '备注',
      dataIndex: 'remark',
      width: 100,
    },
  ];
}

// 4. 生成动态搜索表单配置
export function getSearchFormSchema(): FormSchema[] {
  return [
    {
      field: 'deptId',
      label: '煤矿名称',
      component: 'MineCascader',
      colProps: { span: 6 },
    },
    {
      field: 'fileName',
      label: '图纸名称',
      component: 'Input',
      colProps: { span: 6 },
    },
    {
      field: 'fileType',
      label: '图纸分类',
      component: 'Select',
      componentProps: {
        options: [
          { label: '安全监控部署图', value: '安全监控部署图' },
          { label: '通风系统图', value: '通风系统图' },
          { label: '防灭火图', value: '防灭火图' },
          { label: '人员位置监测系统图', value: '人员位置监测系统图' },
          { label: '采掘工程平面图', value: '采掘工程平面图' },
        ],
      },
      colProps: { span: 6 },
    },
  ];
}

export const formSchema: FormSchema[] = [
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false,
  },
  {
    label: '',
    field: 'filePath',
    component: 'Input',
    show: false,
  },
  {
    label: '',
    field: 'wjId',
    component: 'Input',
    show: false,
  },
  {
    label: '煤矿名称',
    field: 'deptId',
    component: 'MineCascader',
    componentProps: {
      changeOnSelect: false,
      initFromStore: false,
    },
    required: true,
    dynamicRules: () => {
      //需要return
      return [
        {
          //默认开启表单检验
          required: true,
          // value 当前手机号输入的值
          validator: (_, value) => {
            //需要return 一个Promise对象
            const dept = useMineDepartmentStore().findDepartById(value);
            return new Promise((resolve, reject) => {
              if (!dept) {
                reject('请选择部门');
              }
              if (!dept?.isLeaf) {
                reject('请选择具体矿井');
              }
              resolve();
            });
          },
        },
      ];
    },
  },
  {
    label: '文件名称',
    field: 'fileName',
    component: 'Input',
    required: true,
  },
  {
    label: '文件类型',
    field: 'fileType',
    component: 'Select',
    componentProps: {
      options: [
        { label: '安全监控部署图', value: '安全监控部署图' },
        { label: '通风系统图', value: '通风系统图' },
        { label: '防灭火图', value: '防灭火图' },
        { label: '人员位置监测系统图', value: '人员位置监测系统图' },
        { label: '采掘工程平面图', value: '采掘工程平面图' },
      ],
    },
    required: true,
  },
  {
    label: '文件',
    field: 'fileAttach',
    component: 'Input',
    slot: 'fileupload',
    required: true,
    // ifShow({ values }) {
    //   return !values.id;
    // },
  },
  {
    label: '备注',
    field: 'remark',
    component: 'Input',
  },
];

// 地图编辑弹框表单
export const mapEditForm: FormSchema[] = [
  {
    field: 'mineCode',
    label: '煤矿编码',
    component: 'MineCascader',
    colProps: { span: 6 },
    groupName: '常规查询',
    // show: false,
  },
  {
    field: 'mineName',
    label: '煤矿名称',
    component: 'Input',
    colProps: { span: 6 },
    groupName: '常规查询',
  },
  {
    field: 'fileName',
    label: '图纸名称',
    component: 'Input',
    colProps: { span: 6 },
    groupName: '常规查询',
  },

  {
    field: 'fileType',
    label: '图纸类型',
    component: 'Select',
    componentProps: {
      options: [
        { label: '安全监控部署图', value: '安全监控部署图' },
        { label: '通风系统图', value: '通风系统图' },
        { label: '防灭火图', value: '防灭火图' },
        { label: '人员位置监测系统图', value: '人员位置监测系统图' },
        { label: '采掘工程平面图', value: '采掘工程平面图' },
      ],
    },
    colProps: { span: 6 },
    groupName: '常规查询',
  },
  {
    field: 'fileAttach',
    label: '附件',
    component: 'Upload',

    colProps: { span: 6 },
    groupName: '常规查询',
  },
  {
    field: 'remark',
    label: '备注',
    component: 'InputTextArea',
    colProps: { span: 6 },
    groupName: '常规查询',
  },
];
