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.use)(LocaleCtx);
	if (!value) throw new Error("useActiveLocale must be used within a LocaleProvider");
	return value;
}
//#endregion
//#region ../../platform/i18n/src/use-domain-dict.ts
function useDomainDict(domain, locale) {
	const [dict, setDict] = (0, react.useState)(() => domain.getCached(locale) ?? domain.fallback);
	(0, react.useEffect)(() => {
		let cancelled = false;
		if (locale === domain.fallbackLocale) {
			setDict(domain.fallback);
			return;
		}
		const cached = domain.getCached(locale);
		if (cached) {
			setDict(cached);
			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";
	const cache = /* @__PURE__ */ new Map();
	return {
		fallback: config.fallback,
		fallbackLocale,
		getCached(locale) {
			if (locale === fallbackLocale) return config.fallback;
			return cache.get(locale) ?? null;
		},
		async load(locale) {
			if (locale === fallbackLocale) return config.fallback;
			const cached = cache.get(locale);
			if (cached) return cached;
			const loader = config.loaders?.[locale];
			if (!loader) return config.fallback;
			const target = await loader();
			const merged = {
				...config.fallback,
				...target
			};
			cache.set(locale, merged);
			return merged;
		}
	};
}
//#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, "useActiveLocale", {
	enumerable: true,
	get: function() {
		return useActiveLocale;
	}
});
Object.defineProperty(exports, "useDomainDict", {
	enumerable: true,
	get: function() {
		return useDomainDict;
	}
});

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