/**
 * 应急管理公用hook
 */
import { ref } from 'vue';
import type { DeptTree } from '@/types/dept/type';
import type { ApprovalInstanceType } from '@/views/system/approval/types';
import type { SysDictDataDetail } from '@/api/dict';
import { getAllDepartments } from '@/api/auth/dept';
import { getAllApproval } from '@/api/approval/approval';
import { queryDictTypeDetail } from '@/api/dict';
import { DICT_CODE } from '@/constant/dict';
export const useEmergencyHook = () => {
  // 应急事件类型
  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 deptTree = ref<DeptTree[]>();
  const getDeptTreeData = async () => {
    const res = await getAllDepartments();
    deptTree.value = res[0].children;
  };
  // 获取所有审批流程
  const approvalList = ref<ApprovalInstanceType[]>();
  const getApprovalList = async () => {
    approvalList.value = await getAllApproval();
  };
  return {
    emergencyEventDice,
    getEmergencyEventDict,
    getEmergencyEvent,
    deptTree,
    getDeptTreeData,
    approvalList,
    getApprovalList,
  };
};
