import { t as countries_default } from "./countries-Bar7Vz49.js";
//#region editors/invoice/utils/utils.ts
const countriesArray = countries_default;
const getCountryCodeFromName = (countryName) => {
	if (!countryName) return "";
	const specialCases = {
		uk: "GB",
		"united kingdom": "GB",
		england: "GB",
		britain: "GB",
		deutschland: "DE",
		germany: "DE",
		usa: "US",
		"united states of america": "US",
		america: "US"
	};
	const lowerCountryName = countryName.toLowerCase().trim();
	if (specialCases[lowerCountryName]) return specialCases[lowerCountryName];
	if (countryName.length === 2 && /^[A-Z]{2}$/.test(countryName)) {
		if (countriesArray.some((c) => c.cca2 === countryName)) return countryName;
	}
	const exactMatch = countriesArray.find((c) => c.name.common.toLowerCase() === lowerCountryName);
	if (exactMatch) return exactMatch.cca2;
	const officialMatch = countriesArray.find((c) => c.name.official.toLowerCase() === lowerCountryName);
	if (officialMatch) return officialMatch.cca2;
	const nativeMatch = countriesArray.find((c) => {
		if (!c.name.native) return false;
		return Object.values(c.name.native).some((n) => n.common.toLowerCase() === lowerCountryName || n.official.toLowerCase() === lowerCountryName);
	});
	if (nativeMatch) return nativeMatch.cca2;
	const partialMatch = countriesArray.find((c) => c.name.common.toLowerCase().includes(lowerCountryName) || lowerCountryName.includes(c.name.common.toLowerCase()));
	if (partialMatch) return partialMatch.cca2;
	return countryName;
};
const ALCHEMY_RPC = {
	base: "https://base-mainnet.g.alchemy.com/v2",
	ethereum: "https://eth-mainnet.g.alchemy.com/v2",
	arbitrum: "https://arb-mainnet.g.alchemy.com/v2"
};
function alchemyRpc(chain) {
	const apiKey = typeof process !== "undefined" ? process.env?.ALCHEMY_API_KEY : void 0;
	if (!apiKey) return "";
	return `${ALCHEMY_RPC[chain]}/${apiKey}`;
}
function getChainConfigs() {
	return {
		base: {
			chainName: "Base",
			chainId: "8453",
			rpc: alchemyRpc("base") || "https://base-mainnet.public.blastapi.io",
			fallbackRpcs: ["https://base-mainnet.public.blastapi.io", "https://base-rpc.publicnode.com"]
		},
		ethereum: {
			chainName: "Ethereum",
			chainId: "1",
			rpc: alchemyRpc("ethereum") || "https://ethereum-rpc.publicnode.com",
			fallbackRpcs: [
				"https://ethereum-rpc.publicnode.com",
				"https://eth-mainnet.public.blastapi.io",
				"https://1rpc.io/eth"
			]
		},
		"arbitrum one": {
			chainName: "Arbitrum One",
			chainId: "42161",
			rpc: alchemyRpc("arbitrum") || "https://arb1.arbitrum.io/rpc",
			fallbackRpcs: [
				"https://arb1.arbitrum.io/rpc",
				"https://arbitrum-one-rpc.publicnode.com",
				"https://arbitrum-one.public.blastapi.io"
			]
		}
	};
}
/**
* Maps a chain name to its full configuration including chainId and RPC endpoint
* Normalizes case and handles various chain name formats
* @param chainName - Chain name from various sources (Claude AI, user input, etc.)
* @returns ChainConfig object with chainName, chainId, and rpc
*/
function mapChainNameToConfig(chainName) {
	const configs = getChainConfigs();
	const defaultConfig = configs.ethereum;
	if (!chainName) return defaultConfig;
	const normalizedChainName = chainName.toLowerCase().trim();
	if (configs[normalizedChainName]) return configs[normalizedChainName];
	const aliasedName = {
		eth: "ethereum",
		mainnet: "ethereum",
		arb: "arbitrum one",
		arbitrum: "arbitrum one",
		"arb one": "arbitrum one"
	}[normalizedChainName];
	if (aliasedName && configs[aliasedName]) return configs[aliasedName];
	console.warn(`Unknown chain name: "${chainName}". Using default chain: ${defaultConfig.chainName}`);
	return defaultConfig;
}
/**
* Get all available chain configurations as an array
* Useful for UI dropdowns and validation
*/
function getAllChainConfigs() {
	return Object.values(getChainConfigs());
}
//#endregion
export { mapChainNameToConfig as i, getChainConfigs as n, getCountryCodeFromName as r, getAllChainConfigs as t };

//# sourceMappingURL=utils-DfutWF-Y.js.map