'use client';
import { jsx as _jsx } from "react/jsx-runtime";
import { createContext, useContext, useState, useEffect, useCallback } from 'react';
const LocaleContext = createContext({
    activeLocale: 'en',
    setLocale: () => { },
    locales: [],
});
export function useLocale() {
    return useContext(LocaleContext);
}
const STORAGE_KEY = 'actuate-locale';
export function LocaleProvider({ config, children }) {
    const locales = config.i18n?.locales ?? [];
    const defaultLocale = config.i18n?.defaultLocale ?? 'en';
    const [activeLocale, setActiveLocale] = useState(defaultLocale);
    useEffect(() => {
        const stored = localStorage.getItem(STORAGE_KEY);
        if (stored && locales.some((l) => l.code === stored)) {
            setActiveLocale(stored);
        }
    }, [locales]);
    const setLocale = useCallback((locale) => {
        setActiveLocale(locale);
        localStorage.setItem(STORAGE_KEY, locale);
    }, []);
    return (_jsx(LocaleContext.Provider, { value: { activeLocale, setLocale, locales }, children: children }));
}
//# sourceMappingURL=LocaleProvider.js.map