import { FormSchema } from '/@/components/Form';
import { InputRegExp } from '/@/enums/regexpEnum';
export const formSchema: FormSchema[] = [
  {
    field: 'passwordNew',
    label: '新密码',
    component: 'StrengthMeter',
    componentProps: {
      placeholder: '新密码',
    },
    rules: [
      {
        required: true,
        message: '请输入新密码',
      },
    ],
  },
  {
    field: 'confirmPassword',
    label: '确认密码',
    component: 'InputPassword',

    dynamicRules: ({ values }) => {
      return [
        {
          required: true,
          validator: (_, value) => {
            if (!value) {
              return Promise.reject('密码不能为空');
            }
            if (value !== values.passwordNew) {
              return Promise.reject('两次输入的密码不一致!');
            }

            const pwdRegex = new RegExp(InputRegExp.PASSWORD_INPUT);
            if (!pwdRegex.test(value)) {
              return Promise.reject(
                '密码中必须包含大小写 字母、数字、特殊字符，至少8个字符，最多30个字符'
              );
            }
            return Promise.resolve();
          },
        },
      ];
    },
  },
];
