'use client';
import { jsx as _jsx } from "react/jsx-runtime";
import { useEffect } from 'react';
import { I18nextProvider } from 'react-i18next';
import webI18n from '../../lib/i18n.js';
import { applyRtlFont } from '../../lib/rtl-fonts.js';
/**
 * Client-side i18n provider that wraps the application with react-i18next.
 *
 * Receives the initial language from the server-side layout and sets it
 * on the i18next instance. Language changes at runtime (e.g. from settings)
 * call i18n.changeLanguage() which re-renders all translated components.
 *
 * Also handles lazy-loading RTL fonts (Noto Sans Arabic/Hebrew) when the
 * active language requires them.
 */
export function I18nProvider({ initialLanguage, children }) {
    useEffect(() => {
        if (webI18n.language !== initialLanguage) {
            webI18n.changeLanguage(initialLanguage);
        }
        // Apply RTL font for the initial language (lazy-loads if needed)
        applyRtlFont(initialLanguage);
    }, [initialLanguage]);
    // Listen for runtime language changes and apply/remove RTL fonts
    useEffect(() => {
        function onLanguageChanged(lng) {
            applyRtlFont(lng);
        }
        webI18n.on('languageChanged', onLanguageChanged);
        return () => {
            webI18n.off('languageChanged', onLanguageChanged);
        };
    }, []);
    return _jsx(I18nextProvider, { i18n: webI18n, children: children });
}
