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

export default function useGetComment(
  noteID: string,
  isCommentOpened: boolean,
  avatarID?: string,
) {
  const language = useLanguage();

  return useQuery({
    enabled: isCommentOpened,
    queryKey: ["comment", noteID, avatarID, language],
    queryFn: async () => {
      const { data } = await wwwAPI.get<GetCommentAPI>("/comment", {
        params: {
          noteID,
          avatarID,
          language,
        },
      });

      return data;
    },
    initialData: {
      comments: [],
      totalComments: 0,
    },
  });
}
