import { useQuery } from "@tanstack/react-query";
import { wwwAPI } from "@/utilities/wwwAPI";

export default function useGetHit(hitTexts: string[]) {
  return useQuery({
    queryKey: ["hit", hitTexts],
    queryFn: async () => {
      return (
        await Promise.allSettled(
          hitTexts.map(async (hitText) =>
            wwwAPI.get<number>(`/file/${hitText}/hit`),
          ),
        )
      ).map((value) => {
        switch (value.status) {
          case "fulfilled":
            return value.value.data;
          default:
            return 0;
        }
      });
    },
    initialData: [],
  });
}
