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

export default function useGetLatestEssay() {
  const language = useLanguage();

  return useQuery({
    queryKey: ["latestEssay", language],
    queryFn: async () => {
      const { data } = await wwwAPI.get<GetLatestEssayAPI>("/essay/latest", {
        params: { language },
      });
      return data;
    },
    initialData: [],
  });
}
