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

import { ref } from 'vue';

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

import { getLicense } from '#/api/license/license';

import Detail from '../components/detail.vue';

const formData = ref<LicenseApi.License>();

// const [Descriptions] = useDescription({
//   componentProps: {
//     bordered: true,
//     column: 1,
//     class: 'mx-4',
//   },
//   schema: useDetailSchema(),
// });

const [Modal, modalApi] = useVbenModal({
  async onOpenChange(isOpen: boolean) {
    if (!isOpen) {
      formData.value = undefined;
      return;
    }
    // 加载数据
    const data = modalApi.getData<LicenseApi.License>();
    if (!data || !data.id) {
      return;
    }
    // formData.value = data;
    await getDetailById(data.id);
  },
});

const getDetailById = async (id: number) => {
  // 获取详情
  const data = await getLicense(id);
  formData.value = data;
  formData.value.showUpload = true; // 显示上传按钮
};
</script>

<template>
  <Modal
    title="License详情"
    class="w-2/3"
    :show-cancel-button="false"
    :show-confirm-button="false"
  >
    <Detail :form-data="formData" @get-detail-by-id="getDetailById" />
  </Modal>
</template>
