import { FormSchema } from '/@/components/Form';
import { gender } from '/@/utils/filters';

export const InformationFormSchema: FormSchema[] = [
  {
    label: '用户昵称',
    field: 'username',
    required: true,
    component: 'Input',
    componentProps: {
      placeholder: '请输入用户昵称',
    },
  },
  {
    label: '手机号码',
    field: 'phone',
    required: true,
    component: 'Input',
    componentProps: {
      placeholder: '请输入手机号码',
    },
    rules: [{ len: 11 }],
  },
  {
    label: '用户邮箱',
    field: 'email',
    required: true,
    component: 'Input',
    componentProps: {
      placeholder: '请输入用户邮箱',
    },
  },
  {
    label: '性别',
    field: 'gender',
    required: true,
    component: 'RadioGroup',
    componentProps: {
      options: gender,
    },
  },
];
export const pswFormSchema: FormSchema[] = [
  {
    label: '旧密码',
    field: 'oldPsw',
    required: true,
    component: 'InputPassword',
    componentProps: {
      placeholder: '请输入旧密码',
    },
  },
  {
    label: '新密码',
    field: 'newPsw',
    required: true,
    component: 'InputPassword',
    componentProps: {
      placeholder: '请输入新密码',
    },
    rules: [
      {
        min: 6,
      },
    ],
  },
  {
    label: '确认密码',
    field: 'confirmPsw',
    required: true,
    component: 'InputPassword',
    componentProps: {
      rules: [{ min: 6 }],
      placeholder: '请重新输入新密码',
    },
    dynamicRules: ({ values }) => {
      return [
        {
          required: true,
          validator: (_, value) => {
            if (!value) {
              return Promise.reject('不能为空');
            }
            if (value !== values.newPsw) {
              return Promise.reject('两次输入的密码不一致!');
            }
            return Promise.resolve();
          },
        },
      ];
    },
  },
];
