/**
 * 审批流程表单配置
 */

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

export const APPROVAL_FORM_CONFIG: FormConfig[] = [
  {
    label: '审批流程名称：',
    prop: 'templateName',
    component: 'ElInput',
    componentProps: { placeholder: '请输入审批流程名称' },
  },
  {
    label: '审批流程描述：',
    prop: 'description',
    component: 'ElInput',
    componentProps: { placeholder: '请输入审批流程描述' },
  },
];

export const APPROVAL_FORM_DATA = {
  templateName: '',
  description: '',
};

export const APPROVAL_FORM_RULES = {
  templateName: [{ required: true, message: '请输入审批流程名称', trigger: 'blur' }],
};

export const APPROVAL_NODE_FORM_CONFIG: FormConfig[] = [
  {
    label: '节点描述：',
    prop: 'nodeDescription',
    component: 'ElInput',
    componentProps: { placeholder: '请输入节点描述' },
  },
  {
    label: '审批人选择方式：',
    prop: 'approverType',
    component: 'ElSelect',
    selectOptions: [
      {
        label: '固定',
        value: 0,
      },
      {
        label: '自选',
        value: 1,
      },
    ],
  },
  {
    label: '审批方式：',
    prop: 'approvalType',
    component: 'ElSelect',
    selectOptions: [
      {
        label: '会签',
        value: 0,
      },
      {
        label: '或签',
        value: 1,
      },
    ],
  },
  {
    label: '审批节点顺序：',
    prop: 'approvalOrder',
    component: 'ElInputNumber',
    componentProps: {
      min: 1,
    },
  },
];

export const APPROVAL_NODE_FORM_DATA = {
  approvalTemplateId: undefined,
  nodeDescription: '',
  approvalType: 0,
  approverType: 1,
  approvalOrder: undefined,
};

export const APPROVAL_NODE_FORM_RULES = {
  nodeDescription: [
    {
      required: true,
      message: '请输入节点描述',
      trigger: 'blur',
    },
  ],
  approverType: [
    {
      required: true,
      message: '请选择审批人选择方式',
      trigger: 'change',
    },
  ],
  approvalType: [
    {
      required: true,
      message: '请选择审批方式',
      trigger: 'change',
    },
  ],
  approvalOrder: [
    {
      required: true,
      // validator: (rule: any, value: any, callback: any, existingNumbers: number[]) => {
      //   // 检查输入值是否与已有数组中的任何元素重复
      //   if (value === null || value === undefined || value === '') {
      //     callback(); // 空值校验由required规则处理
      //     return;
      //   }
      //   if (existingNumbers.includes(Number(value))) {
      //     callback(new Error('该顺序已存在，请重新输入'));
      //   } else {
      //     callback();
      //   }
      // },
      message: '请输入审批节点顺序',
      trigger: 'blur',
    },
  ],
};
