import { useConfig } from "@hooks/useConfig";
import { useQuery } from "@tanstack/react-query";
import { bungeeApiFetcher } from "@utils/fetcher";

export const useChains = () => {
	const { baseUrl, apiKey } = useConfig();
	// biome-ignore format: some error with biome I'm gussing
	const query = `${baseUrl}/supported-chains`;

	const { data } = useQuery({
		queryKey: ["supported-chains", query, apiKey],
		queryFn: () => bungeeApiFetcher(query, apiKey),
		refetchOnWindowFocus: false,
		refetchOnMount: false,
		retry: 2,
		staleTime: 300000, // 5 minutes
	});

	return data?.result;
};
