'use strict';

require('../../../api/guardBasic/controller/index.js');
var vue = require('vue');
var core = require('@vueuse/core');
var usePostBasicV1DataDictionaryBatchDetailByCode = require('../../../api/guardBasic/controller/JiChuFuWu/ShuJuZiDianGuanLi/usePostBasicV1DataDictionaryBatchDetailByCode.js');

const useDictionary = (fieldCodes, options) => {
  const { exec: getDictionaryExec } = usePostBasicV1DataDictionaryBatchDetailByCode.usePostBasicV1DataDictionaryBatchDetailByCode();
  const isLoading = vue.ref(false);
  const dictionaryList = vue.ref([]);
  const dictionary = vue.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;
  core.tryOnMounted(() => {
    if (immediate) {
      getDictionary();
    }
  });
  return {
    dictionaryList,
    dictionary,
    isLoading,
    getDictionary
  };
};

exports.useDictionary = useDictionary;
//# sourceMappingURL=index.js.map
