import { queryClient } from '../commands/_app.js';
import { queryChainConfig } from './chainConfig.js';
import { CHAIN_LIST_URL, } from '../superchain-registry/fetchChainList.js';
import { useQuery } from '@tanstack/react-query';
const getQueryParams = (chainListURL) => {
    return {
        queryKey: ['chainListItemByIdentifier', chainListURL],
        queryFn: async () => {
            const chainList = await queryChainConfig(chainListURL);
            return chainList.reduce((acc, config) => {
                acc[config.identifier] = config;
                return acc;
            }, {});
        },
    };
};
export const queryMappingChainListItemByIdentifier = async (chainListURL = CHAIN_LIST_URL) => {
    return queryClient.fetchQuery(getQueryParams(chainListURL));
};
export const useMappingChainListItemByIdentifier = (chainListURL = CHAIN_LIST_URL) => {
    return useQuery({
        ...getQueryParams(chainListURL),
        staleTime: Infinity, // For the duration of the CLI session, this is cached
    });
};
