'use strict';

var vue = require('vue');
var pinia = require('pinia');
var lodashEs = require('lodash-es');
var core = require('@vueuse/core');
require('../../../../api/guardBasic/controller/index.js');
var usePostBasicV1SysAreaListFamilyArea = require('../../../../api/guardBasic/controller/JiChuFuWu/TuanDuiGuanLi/usePostBasicV1SysAreaListFamilyArea.js');

const useAreaListStore = pinia.defineStore("gmAreaList", () => {
  const { isLoading, exec } = usePostBasicV1SysAreaListFamilyArea.usePostBasicV1SysAreaListFamilyArea();
  const areaList = core.useSessionStorage("gmAreaList", [], { listenToStorageChanges: false });
  const familyAreaList = vue.computed(() => {
    const familyGroup = lodashEs.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 || [];
    }
  };
  core.tryOnMounted(() => {
    if (areaList.value.length !== 0 || isLoading.value) {
      return;
    }
    getAreaList();
  });
  return {
    areaList,
    isLoading,
    familyAreaList,
    getAreaList
  };
});

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