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

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

const useAuthUser = () => {
  const state = reactive({
    showDropDownBox: false,
    available_uids: ref<IUserItem[]>([])
  });

  const initData = async () => {
    try {
      const { data } = await getAuthorUser();
      state.available_uids = data.available_uids;
      state.showDropDownBox = data.showDropDownBox;
      console.log(state);
    } catch (error) {
      console.log("error happened in get auth user:", error.message);
    }
  };

  watchEffect(initData);

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

export default useAuthUser;
