<template>
  <BasicModal v-bind="$attrs" @register="registerModal" title="修改密码" @ok="handleSubmit" width="600px">
    <BasicForm @register="registerForm" />
  </BasicModal>
</template>
<script lang="ts" setup>
  import { rules } from '/@/utils/helper/validator';
  import { BasicModal, useModalInner } from '/@/components/Modal';
  import BasicForm from '/@/components/Form/src/BasicForm.vue';
  import { useForm } from '/@/components/Form/src/hooks/useForm';

  // 声明Emits
  const emit = defineEmits(['register', 'submit']);
  //表单配置
  const [registerForm, { validate }] = useForm({
    schemas: [
      {
        label: '旧密码',
        field: 'oldpassword',
        component: 'InputPassword',
        required: true,
      },
      {
        label: '新密码',
        field: 'password',
        component: 'InputPassword',
        // component: 'StrengthMeter',
        componentProps: {
          placeholder: '请输入新密码',
        },
        rules: [
          {
            required: true,
            message: '请输入新密码',
          },
        ],
      },
      {
        label: '确认新密码',
        field: 'confirmpassword',
        component: 'InputPassword',
        dynamicRules: ({ values }) => rules.confirmPassword(values, true),
      },
    ],
    showActionButtonGroup: false,
  });
  //表单赋值
  const [registerModal] = useModalInner();

  //表单提交事件
  async function handleSubmit() {
    const values = await validate();
    emit('submit', values);
  }
</script>
