<script lang="ts" setup>
/**
 * 审方页处方溯源弹窗
 */
import { ref } from 'vue';

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

import PrescriptionSourceContent from '#/components/prescription-source/PrescriptionSourceContent.vue';

import { getPrescriptionSourceApi } from '../api';

defineOptions({ name: 'PrescriptionSource' });

const data = ref<Record<string, any> | null>(null);

const [Modal, modalApi] = useVbenModal({
  fullscreenButton: false,
  draggable: true,
  onCancel() {
    modalApi.close();
  },
  onConfirm: async () => {
    modalApi.close();
  },
  onOpenChange(isOpen: boolean) {
    const payload = modalApi.getData<Record<string, any>>();
    if (isOpen && payload?.id) {
      getPrescriptionSourceApi({ id: payload.id }).then((res) => {
        data.value = res;
      });
    } else {
      data.value = null;
    }
  },
});
</script>

<template>
  <Modal class="w-[80%] h-[80%]" title="处方溯源">
    <PrescriptionSourceContent :data="data" />
  </Modal>
</template>
