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

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

export default function useGetAvatarWwwLevels(avatarID?: string) {
  const { pathname } = useLocation();

  return useQuery({
    enabled: !!avatarID && pathname.startsWith("/qwilight/avatar"),
    queryKey: ["avatarWwwLevels", avatarID],
    queryFn: async () => {
      const { data } = await wwwAXIOS.get<GetAvatarWwwLevelsAPI>(
        "/avatar/wwwLevels",
        {
          params: { avatarID },
        },
      );
      return data;
    },
    initialData: [],
  });
}
