import '../../../api/guardBasic/controller/index.mjs';
import { ref, computed } from 'vue';
import { tryOnMounted } from '@vueuse/core';
import { usePostBasicV1DataDictionaryBatchDetailByCode } from '../../../api/guardBasic/controller/JiChuFuWu/ShuJuZiDianGuanLi/usePostBasicV1DataDictionaryBatchDetailByCode.mjs';

const useDictionary = (fieldCodes, options) => {
  const { exec: getDictionaryExec } = usePostBasicV1DataDictionaryBatchDetailByCode();
  const isLoading = ref(false);
  const dictionaryList = ref([]);
  const dictionary = computed(() => {
    return dictionaryList.value.reduce(
      (acc, item) => {
        acc[item.fieldCode] = item?.values?.map((it) => ({
          label: it.valueName,
          value: it.valueCode,
          tagType: it.tagType
        })) || [];
        return acc;
      },
      {}
    );
  });
  const getDictionary = async () => {
    isLoading.value = true;
    try {
      const { data } = await getDictionaryExec({ fieldCodes });
      dictionaryList.value = data.value?.data || [];
    } finally {
      isLoading.value = false;
    }
  };
  const immediate = options?.immediate ?? true;
  tryOnMounted(() => {
    if (immediate) {
      getDictionary();
    }
  });
  return {
    dictionaryList,
    dictionary,
    isLoading,
    getDictionary
  };
};

export { useDictionary };
//# sourceMappingURL=index.mjs.map
