import { computed } from 'vue';
import { defineStore } from 'pinia';
import { groupBy } from 'lodash-es';
import { useSessionStorage, tryOnMounted } from '@vueuse/core';
import '../../../../api/guardBasic/controller/index.mjs';
import { usePostBasicV1SysAreaListFamilyArea } from '../../../../api/guardBasic/controller/JiChuFuWu/TuanDuiGuanLi/usePostBasicV1SysAreaListFamilyArea.mjs';

const useAreaListStore = defineStore("gmAreaList", () => {
  const { isLoading, exec } = usePostBasicV1SysAreaListFamilyArea();
  const areaList = useSessionStorage("gmAreaList", [], { listenToStorageChanges: false });
  const familyAreaList = computed(() => {
    const familyGroup = groupBy(areaList.value, "family_code");
    return Object.keys(familyGroup).map((familyCode) => {
      return {
        label: familyGroup[familyCode][0].family_name,
        value: familyCode,
        children: familyGroup[familyCode].map((it) => ({ label: it.name, value: it.id }))
      };
    });
  });
  const getAreaList = async (input) => {
    const res = await exec(input);
    if (res.data.value?.code == 200) {
      areaList.value = res.data.value?.data || [];
    }
  };
  tryOnMounted(() => {
    if (areaList.value.length !== 0 || isLoading.value) {
      return;
    }
    getAreaList();
  });
  return {
    areaList,
    isLoading,
    familyAreaList,
    getAreaList
  };
});

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