<script setup lang="ts">
import type {ContingenPlanVO} from '#/api/property/customerService/contingenPlan/model';
import {shallowRef} from 'vue';
import {useVbenModal} from '@vben/common-ui';
import {Descriptions, DescriptionsItem} from 'ant-design-vue';
import {contingenPlanInfo} from '#/api/property/customerService/contingenPlan';
import {renderDict} from "#/utils/render";

const [BasicModal, modalApi] = useVbenModal({
  onOpenChange: handleOpenChange,
  onClosed() {
    contingenPlanIDetail.value = null;
  },
});

const contingenPlanIDetail = shallowRef<null | ContingenPlanVO>(null);

async function handleOpenChange(open: boolean) {
  if (!open) {
    return null;
  }
  modalApi.modalLoading(true);
  const {id} = modalApi.getData() as { id: number | string };
  const response = await contingenPlanInfo(id);
  contingenPlanIDetail.value = response;
  modalApi.modalLoading(false);
}
</script>

<template>
  <BasicModal :footer="false" :fullscreen-button="false" title="详情" class="w-[70%]">
    <Descriptions v-if="contingenPlanIDetail" size="small" :column="2" bordered :labelStyle="{width:'100px'}">
      <DescriptionsItem label="预案名称">
        {{ contingenPlanIDetail.contingenPlanName }}
      </DescriptionsItem>
      <DescriptionsItem label="预案类型" v-if="contingenPlanIDetail.contingenPlanType!=null">
        <component
          :is="renderDict(contingenPlanIDetail.contingenPlanType,'type_contingency_plan')"
        />
      </DescriptionsItem>
      <DescriptionsItem label="发起人">
        {{ contingenPlanIDetail.initiat }}
      </DescriptionsItem>
      <DescriptionsItem label="演练状态" v-if="contingenPlanIDetail.status!=null">
        <component
          :is="renderDict(contingenPlanIDetail.status,'pro_exercise_status')"
        />
      </DescriptionsItem>
      <DescriptionsItem label="责任人">
        {{ contingenPlanIDetail.dutyPersion}}
      </DescriptionsItem>
      <DescriptionsItem label="完成时间">
        {{ contingenPlanIDetail.compleTimes }}
      </DescriptionsItem>
    </Descriptions>
  </BasicModal>
</template>
