import { GetForumsAPI } from "@/type/wwwAPI";
import { wwwAPI } from "@/utilities/wwwAPI";
import { useQuery } from "@tanstack/react-query";
import { useLanguage } from "taehui-lib/language";

export default function useGetForums(forumGroup?: string) {
  const language = useLanguage();

  return useQuery({
    queryKey: ["forums", forumGroup, language],
    queryFn: async () => {
      const { data } = await wwwAPI.get<GetForumsAPI>(
        forumGroup ? `/forums/${forumGroup}` : "/forums",
        {
          params: { language },
        },
      );
      return data;
    },
    initialData: [],
  });
}
