import { jsx } from "react/jsx-runtime";
import { createContext, useContext, useEffect, useMemo, useState } from "react";
import { AutopilotChatInternalEvent } from "../service/ChatModel.js";
import { useChatService } from "./chat-service.provider.js";
const LocaleContext = /*#__PURE__*/ createContext(void 0);
const LocaleProvider = ({ children })=>{
    const chatService = useChatService();
    const [locale, setLocale] = useState(chatService.getLocale());
    useEffect(()=>{
        const unsubscribe = chatService.__internalService__.on(AutopilotChatInternalEvent.SetLocale, (newLocale)=>{
            setLocale(newLocale);
        });
        return ()=>{
            unsubscribe();
        };
    }, [
        chatService
    ]);
    const value = useMemo(()=>({
            locale
        }), [
        locale
    ]);
    return /*#__PURE__*/ jsx(LocaleContext.Provider, {
        value: value,
        children: children
    });
};
const useLocale = ()=>{
    const context = useContext(LocaleContext);
    if (!context) throw new Error('useLocale must be used within a LocaleProvider');
    return context;
};
export { LocaleProvider, useLocale };
