require("./chunk-9hOWP6kD.cjs");
let react = require("react");
let react_jsx_runtime = require("react/jsx-runtime");
//#region ../../platform/i18n/src/locale-context.tsx
const LocaleCtx = (0, react.createContext)(null);
function LocaleProvider({ initialLocale, onLocaleChange, children }) {
	const [locale, setLocaleState] = (0, react.useState)(initialLocale);
	const value = (0, react.useMemo)(() => ({
		locale,
		setLocale(next) {
			setLocaleState(next);
			onLocaleChange?.(next);
		}
	}), [locale, onLocaleChange]);
	return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(LocaleCtx.Provider, {
		value,
		children
	});
}
function useActiveLocale() {
	const value = (0, react.useContext)(LocaleCtx);
	if (!value) throw new Error("useActiveLocale must be used within a LocaleProvider");
	return value;
}
//#endregion
//#region ../../platform/i18n/src/translation-api-context-factory.ts
function createTranslationContext(domainName) {
	const Ctx = (0, react.createContext)(null);
	function useTranslation() {
		const api = (0, react.useContext)(Ctx);
		if (!api) throw new Error(`use${domainName}Translation must be used within a ${domainName}TranslationProvider`);
		return api;
	}
	return {
		Context: Ctx,
		Provider: Ctx.Provider,
		useTranslation
	};
}
//#endregion
//#region ../../platform/i18n/src/use-domain-dict.ts
function useDomainDict(domain, locale) {
	const [dict, setDict] = (0, react.useState)(domain.fallback);
	(0, react.useEffect)(() => {
		let cancelled = false;
		if (locale === domain.fallbackLocale) {
			setDict(domain.fallback);
			return;
		}
		domain.load(locale).then((next) => {
			if (!cancelled) setDict(next);
		}).catch(() => {
			if (!cancelled) setDict(domain.fallback);
		});
		return () => {
			cancelled = true;
		};
	}, [domain, locale]);
	return dict;
}
//#endregion
//#region ../../platform/i18n/src/translations.ts
function createDomainTranslations(config) {
	const fallbackLocale = config.fallbackLocale ?? "en";
	return {
		fallback: config.fallback,
		fallbackLocale,
		async load(locale) {
			if (locale === fallbackLocale) return config.fallback;
			const loader = config.loaders?.[locale];
			if (!loader) return config.fallback;
			const target = await loader();
			return {
				...config.fallback,
				...target
			};
		}
	};
}
//#endregion
//#region ../../platform/i18n/src/static-dict-adapter.ts
function createStaticDictAdapter(locale, dict) {
	return {
		locale,
		t(key, ...args) {
			const template = dict[key] ?? key;
			const params = args[0];
			if (!params) return template;
			return template.replace(/\{\{(\w+)\}\}/g, (match, name) => name in params ? String(params[name]) : match);
		}
	};
}
//#endregion
Object.defineProperty(exports, "LocaleProvider", {
	enumerable: true,
	get: function() {
		return LocaleProvider;
	}
});
Object.defineProperty(exports, "createDomainTranslations", {
	enumerable: true,
	get: function() {
		return createDomainTranslations;
	}
});
Object.defineProperty(exports, "createStaticDictAdapter", {
	enumerable: true,
	get: function() {
		return createStaticDictAdapter;
	}
});
Object.defineProperty(exports, "createTranslationContext", {
	enumerable: true,
	get: function() {
		return createTranslationContext;
	}
});
Object.defineProperty(exports, "useActiveLocale", {
	enumerable: true,
	get: function() {
		return useActiveLocale;
	}
});
Object.defineProperty(exports, "useDomainDict", {
	enumerable: true,
	get: function() {
		return useDomainDict;
	}
});

//# sourceMappingURL=static-dict-adapter-D1ErNskC.cjs.map