/** @license MIT | @cube-dev/ui-kit v0.147.0 | Cube Dev Team */
import { UIKIT_I18N_NAMESPACE, getI18n } from "./instance.js";
import { jsx } from "react/jsx-runtime";
import { I18nProvider } from "react-aria";
import { I18nextProvider, useTranslation } from "react-i18next";

//#region src/i18n/I18nProvider.tsx
/**
* The UI Kit's single i18n provider. It wires up **both** localization layers
* from one place:
*
* - `<I18nextProvider>` — supplies the selected i18next instance for translated
*   strings (`useTranslation`, `Trans`, ...).
* - React Aria's `<I18nProvider>` — supplies the locale that React Aria's
*   formatting hooks read (`useLocale`, `useDateFormatter`, `useNumberFormatter`,
*   `useCollator`, `useFilter`, ...).
*
* These are two independent library contexts, so they can't be a single physical
* provider — but the language is one concept, owned by the i18next instance. This
* component makes the instance the single source of truth and *derives* React
* Aria's locale from it, so a host calling `getI18n().changeLanguage('de-DE')`
* gets German labels **and** German number/date formatting with no extra setup.
* The locale bridge re-renders on `languageChanged`, keeping the two in sync
* automatically.
*/
function AriaLocaleBridge({ children, i18n, locale }) {
	const { i18n: activeI18n } = useTranslation(UIKIT_I18N_NAMESPACE, { i18n });
	return /* @__PURE__ */ jsx(I18nProvider, {
		locale: locale ?? activeI18n.resolvedLanguage ?? activeI18n.language,
		children
	});
}
function I18nProvider$1({ children, i18n = getI18n(), locale }) {
	return /* @__PURE__ */ jsx(I18nextProvider, {
		i18n,
		children: /* @__PURE__ */ jsx(AriaLocaleBridge, {
			i18n,
			locale,
			children
		})
	});
}

//#endregion
export { I18nProvider$1 as I18nProvider };
//# sourceMappingURL=I18nProvider.js.map