<script setup lang="ts">
import type { UserApi } from '#/api';

import { ref } from 'vue';

import { useVbenModal } from '@vben/common-ui';

import { Input } from 'ant-design-vue';

import { resetPasswordApi } from '#/api';

const emits = defineEmits(['success']);
const userId = ref();
const resetpasswordData = ref();
const formData = ref();

const [Modal, modalApi] = useVbenModal({
  async onConfirm() {
    if (!resetpasswordData.value) return;

    modalApi.lock();
    try {
      await resetPasswordApi(userId.value, {
        password: resetpasswordData.value,
      });
      emits('success');
      modalApi.close();
    } finally {
      modalApi.lock(false);
    }
  },
  onOpenChange(isOpen) {
    if (isOpen) {
      formData.value = modalApi.getData<UserApi.User>();
      userId.value = formData.value.id;
    }
  },
});
</script>

<template>
  <Modal title="重置密码" class="flex flex-col">
    <Input.Password
      class="my-4"
      placeholder="请输入密码"
      v-model:value="resetpasswordData"
    />
  </Modal>
</template>

<style scoped></style>
