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

const useOrgUserListStore = defineStore("gmOrgUserList", () => {
  const { isLoading, exec, data: userListData } = usePostBasicV1UserListUserOrg();
  const userList = computed(() => userListData.value?.data || []);
  const orgUserList = computed(() => {
    const familyGroup = groupBy(userList.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.user_name, value: it.user_id }))
      };
    });
  });
  const getOrgUserList = async (input) => {
    return exec(input);
  };
  tryOnMounted(() => {
    if (userList.value.length !== 0 || isLoading.value) {
      return;
    }
    getOrgUserList({ user_status: 1 });
  });
  return {
    userList,
    isLoading,
    orgUserList,
    getOrgUserList
  };
});

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