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

export const INVENTORY_FORM_CONFIG: FormConfig[] = [
  {
    prop: 'itemName',
    label: '物品名称：',
    component: 'ElInput',
    componentProps: {
      placeholder: '请输入物品名称',
    },
  },
  {
    prop: 'warehouseDate',
    label: '入库日期：',
    component: 'ElDatePicker',
    componentProps: {
      type: 'date',
      placeholder: '请选择入库日期',
      valueFormat: 'YYYY-MM-DD',
    },
  },
  {
    prop: 'itemQuantity',
    label: '物品数量：',
    component: 'ElInputNumber',
    componentProps: {
      min: 1,
      precision: 0, // 不允许小数点，只能输入整数
      placeholder: '请输入物品数量',
    },
  },
  {
    label: '备注：',
    prop: 'remarks',
    component: 'ElInput',
    componentProps: {
      type: 'textarea',
      rows: 5,
      placeholder: '请输入备注',
    },
  },
];

export const INVENTORY_FORM_DATA = {
  itemName: '',
  warehouseDate: '',
  itemQuantity: 1, // 最小值为1
  remarks: '',
};

export const FORM_RULES = {
  trainingPlanName: [
    { required: true, message: '请输入生产安全计划名称', trigger: 'blur' },
    { min: 1, max: 100, message: '长度在 1 到 100 个字符', trigger: 'blur' },
  ],
  categoryName: [{ required: true, message: '请选择分类名称', trigger: 'change' }],
  responsibleDeptIds: [
    {
      required: true,
      validator(_rule, value, callback) {
        const empty =
          value === '' || value === null || value === undefined || (Array.isArray(value) && value.length === 0);
        if (empty) callback(new Error('请选择责任部门'));
        else callback();
      },
      trigger: 'change',
    },
  ],
  cooperateDeptIds: [
    {
      required: true,
      validator(_rule, value, callback) {
        const empty =
          value === '' || value === null || value === undefined || (Array.isArray(value) && value.length === 0);
        if (empty) callback(new Error('请选择配合部门'));
        else callback();
      },
      trigger: 'change',
    },
  ],
  plannedComplateTime: [{ required: true, message: '请选择计划完成时间', trigger: 'change' }],
  workContent: [
    { required: true, message: '请填写工作内容', trigger: 'blur' },
    { min: 1, max: 300, message: '工作内容长度在 1 到 300 个字符', trigger: 'blur' },
  ],
  fileUrl: [
    {
      required: true,
      validator(_rule, value, callback) {
        const empty = !value || (typeof value === 'string' && !value.trim());
        if (empty) callback(new Error('请上传附件'));
        else callback();
      },
      trigger: 'change',
    },
  ],
};
