import { useQuery } from "@tanstack/react-query";
import { getLanguage } from "taehui-ts/language";

import { wwwAXIOS } from "src/Www";
import { GetForumsAPI } from "src/wwwAPI";

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