//#region src/loader.ts
var BundleLoadError = class extends Error {
	locale;
	namespace;
	constructor(locale, namespace) {
		super(namespace ? `BundleLoadError: no bundle for locale "${locale}" namespace "${namespace}"` : `BundleLoadError: no bundle for locale "${locale}"`);
		this.locale = locale;
		this.namespace = namespace;
		this.name = "BundleLoadError";
	}
};
function cacheKey(locale, namespace) {
	return namespace ? `${locale}:${namespace}` : locale;
}
function createBundleLoader(loadFn) {
	const cache = /* @__PURE__ */ new Map();
	return {
		async load(locale, namespace) {
			const key = cacheKey(locale, namespace);
			const hit = cache.get(key);
			if (hit) return hit;
			const bundle = await loadFn(locale, namespace);
			if (!bundle) throw new BundleLoadError(locale, namespace);
			cache.set(key, bundle);
			return bundle;
		},
		peek(locale, namespace) {
			return cache.get(cacheKey(locale, namespace));
		},
		clear() {
			cache.clear();
		}
	};
}
//#endregion
export { BundleLoadError, createBundleLoader };
