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 ThemeContext = /*#__PURE__*/ createContext(void 0);
const ThemeProvider = ({ children })=>{
    const chatService = useChatService();
    const [theme, setTheme] = useState(chatService.getTheme());
    useEffect(()=>{
        const unsubscribe = chatService.__internalService__.on(AutopilotChatInternalEvent.SetTheme, (newTheme)=>{
            setTheme(newTheme);
        });
        return ()=>{
            unsubscribe();
        };
    }, [
        chatService
    ]);
    const value = useMemo(()=>({
            theme,
            isDark: theme.startsWith('dark')
        }), [
        theme
    ]);
    return /*#__PURE__*/ jsx(ThemeContext.Provider, {
        value: value,
        children: children
    });
};
const useTheme = ()=>{
    const context = useContext(ThemeContext);
    if (!context) throw new Error('useTheme must be used within a ThemeProvider');
    return context;
};
export { ThemeProvider, useTheme };
