/**
 * @description: 应急处置
 */
import { ref } from 'vue';
import type { SysDictDataDetail } from '@/api/dict';
import { queryDictTypeDetail } from '@/api/dict';
import { DICT_CODE } from '@/constant/dict';
import { EMERGENCY_PROCEDURE_STATUS_OPTIONS } from '../constant';

export const useEmergencyProcedureHook = () => {
  // 应急事件类型
  const emergencyEventDice = ref<SysDictDataDetail[]>([]);
  const getEmergencyEventDict = async () => {
    const emergencyEventRes = await queryDictTypeDetail(DICT_CODE.EMERGENCY_EVENT);
    emergencyEventDice.value = emergencyEventRes.sysDictDataList;
  };

  // 获取应急事件类型字典
  const getEmergencyEvent = (emergencyType: string) => {
    return emergencyEventDice.value.find((item) => item.itemCode === emergencyType)?.itemValue;
  };

  // 状态映射
  const getEmergencyStatus = (status: number) => {
    return EMERGENCY_PROCEDURE_STATUS_OPTIONS.find((item) => item.value === status)?.label;
  };
  return {
    emergencyEventDice,
    getEmergencyEventDict,
    getEmergencyEvent,
    getEmergencyStatus,
  };
};
