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

import { wwwAXIOS } from "src/Www";
import { GetAvatarFavoritesAPI } from "src/wwwAPI";

export default function useGetAvatarFavorites(
  inputMode: "6K" | "5K" | "7K" | "9K" | "10K" | "14K" | "24K" | "48K",
  avatarID?: string,
) {
  const { pathname } = useLocation();

  return useQuery({
    enabled: !!avatarID && pathname.startsWith("/qwilight/avatar"),
    queryKey: ["avatarFavorites", inputMode, avatarID],
    queryFn: async () => {
      const { data } = await wwwAXIOS.get<GetAvatarFavoritesAPI>(
        `/avatar/favorites/${inputMode}`,
        {
          params: { avatarID },
        },
      );
      return data;
    },
    initialData: [],
  });
}
