import { jsx } from "react/jsx-runtime";
import { i18n } from "@lingui/core";
import { I18nProvider } from "@lingui/react";
import { useCallback, useEffect } from "react";
import { getAllPreImportedLocales } from "./locale-registry.js";
const SUPPORTED_LOCALES = [
    'en',
    'es',
    'pt',
    'de',
    'fr',
    'ja',
    'ko',
    'ru',
    'tr',
    'zh-CN',
    'zh-TW',
    'pt-BR',
    'es-MX'
];
function ApI18nProvider({ component, locale: propLocale, children }) {
    const locale = propLocale || 'en';
    const loadAndActivate = useCallback(()=>{
        const preImportedLocales = getAllPreImportedLocales(component);
        if (!preImportedLocales) {
            console.error(`No locales found for component: ${component}`);
            i18n.load(locale, {});
            i18n.activate(locale);
            return;
        }
        SUPPORTED_LOCALES.forEach((supportedLocale)=>{
            const messages = preImportedLocales[supportedLocale];
            if (messages) i18n.load(supportedLocale, messages);
        });
        i18n.activate(locale);
    }, [
        component,
        locale
    ]);
    useEffect(()=>{
        loadAndActivate();
    }, [
        loadAndActivate
    ]);
    return /*#__PURE__*/ jsx(I18nProvider, {
        i18n: i18n,
        children: children
    });
}
function useApI18n() {
    return i18n;
}
export { ApI18nProvider, SUPPORTED_LOCALES, useApI18n };
