import { Apis } from '@/gen/Apis';
import { ModalForm, ProFormText } from '@ant-design/pro-components';
import { message } from 'antd';

export default function ChangePassword({
  open,
  setOpen,
}: {
  open: boolean;
  setOpen: (open: boolean) => void;
}) {
  return (
    <ModalForm<ApiTypes.Common.Auth.ChangePassword>
      open={open}
      wrapperCol={{ span: 24 }}
      width="500px"
      title="修改密码"
      onFinish={async (values) => {
        return Apis.Common.Auth.ChangePassword(values)
          .then(() => {
            message.success('修改密码成功');
            setOpen(false);
          })
          .catch(() => false);
      }}
      modalProps={{
        onCancel: () => setOpen(false),
      }}
    >
      <ProFormText.Password name="old_password" label="原密码" required />
      <ProFormText.Password name="new_password" label="新密码" required />
      <ProFormText.Password
        name="re_new_password"
        label="重复新密码"
        required
      />
    </ModalForm>
  );
}
