/**
 * 应急预案公用hook
 */
import { ref } from 'vue';
import type { SysDictDataDetail } from '@/api/dict';
import { queryDictTypeDetail } from '@/api/dict';
import { DICT_CODE } from '@/constant/dict';
import { EMERGENCY_PLAN_STATUS_OPTIONS, APPROVAL_STATUS_OPTIONS } from './constant';
export const useEmergencyPlanHook = () => {
  // 预案类型
  const planTypeDice = ref<SysDictDataDetail[]>([]);
  const getPlanTypeDict = async () => {
    const planTypeRes = await queryDictTypeDetail(DICT_CODE.PLAN_TYPE);
    planTypeDice.value = planTypeRes.sysDictDataList;
  };
  const getPlanType = (planType: string) => {
    return planTypeDice.value.find((item) => item.itemCode === planType)?.itemValue;
  };
  const getEmergencyPlanStatusLabel = (status: number) => {
    return EMERGENCY_PLAN_STATUS_OPTIONS.find((item) => item.value === status)?.label;
  };
  const getEmergencyPlanApproStatusLabel = (status: number) => {
    return APPROVAL_STATUS_OPTIONS.find((item) => item.value === status)?.label;
  };
  return {
    planTypeDice,
    getPlanTypeDict,
    getPlanType,
    getEmergencyPlanStatusLabel,
    getEmergencyPlanApproStatusLabel,
  };
};
