import { useQuery } from "@tanstack/react-query";
import { useLocation } from "react-router-dom";
import { sprintf } from "sprintf-js";

import { wwwAXIOS } from "src/Www";
import { GetHOFAPI } from "src/wwwAPI";
import { useHOFStore } from "src/Stores";
import { formatText } from "src/Utility";

export default function useGetAbility7KHOF() {
  const { tabPosition, abilityTabPosition } = useHOFStore();

  const { pathname } = useLocation();

  return useQuery<
    {
      avatarID: string;
      avatarName: string;
      text: string;
    }[]
  >({
    enabled:
      tabPosition === 2 &&
      abilityTabPosition === 1 &&
      pathname.startsWith("/qwilight/hof"),
    queryKey: ["ability7KHOF"],
    queryFn: async () => {
      const { data } = await wwwAXIOS.get<GetHOFAPI[]>("/hof/ability/7K");
      return data.map((hof) => ({
        ...hof,
        text: sprintf(sprintf("%s Point", formatText(hof.value))),
      }));
    },
    initialData: [],
  });
}
