import { useQuery } from "@tanstack/react-query";
import { wwwAXIOS } from "src/Www";

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