import { reactive, ref, toRefs, watchEffect } from "vue";

import { IUserItem, IGroupItem } from "#/api";
import { getAuthorUser } from "@/api";

const useAuthUser = () => {
  const state = reactive({
    showDropDownBox: false,
    available_uids: ref<IUserItem[]>([]),
    filter_users: [],
  });
  const initData = async () => {
    try {
      const { data } = await getAuthorUser();
      state.available_uids = data.available_uids;
      state.showDropDownBox = data.showDropDownBox;

      console.log(data.filter_users);
      localStorage.setItem("filter_users", data.filter_users);
    } catch (error) {
      console.log("error happened in get auth user:", error.message);
    }
  };

  watchEffect(initData);

  return { ...toRefs(state) };
};

export default useAuthUser;
