import { built_default } from "../config/dist/esm/built.mjs";

//#region ../react-intlayer/dist/esm/@intlayer/core/dist/esm/localization/localeResolver.mjs
/**
* Resolves the most specific locale from a user-provided list,
* or falls back to the default locale if no match is found.
*/
const localeResolver = (selectedLocale, locales = built_default?.internationalization?.locales, defaultLocale = built_default?.internationalization?.defaultLocale) => {
	const requestedLocales = [selectedLocale].flat();
	const normalize = (locale) => locale.trim().toLowerCase();
	try {
		for (const requested of requestedLocales) {
			const normalizedRequested = normalize(requested);
			const exactMatch = locales.find((loc) => normalize(loc) === normalizedRequested);
			if (exactMatch) return exactMatch;
			const [requestedLang] = normalizedRequested.split("-");
			const partialMatch = locales.find((loc) => normalize(loc).split("-")[0] === requestedLang);
			if (partialMatch) return partialMatch;
		}
	} catch (_error) {}
	return defaultLocale;
};

//#endregion
export { localeResolver };
//# sourceMappingURL=localeResolver.mjs.map