import { useQuery } from "@tanstack/react-query";
import { wwwAXIOS } from "src/Www";
import { GetForumAPI } from "src/wwwAPI";
import { getLanguage } from "taehui-ts/language";

export default function useGetForum(
  forumID: string,
  page: number,
  viewUnit: number,
) {
  const language = getLanguage();

  return useQuery({
    queryKey: ["forum", forumID, page, viewUnit, language],
    queryFn: async () => {
      const { data } = await wwwAXIOS.get<GetForumAPI>(`/forum/${forumID}`, {
        params: {
          page,
          viewUnit,
          language,
        },
      });
      return data;
    },
    initialData: {
      title: "",
      text: "",
      essays: [],
      essayCount: 0,
      level: 0,
    },
  });
}
