import { jsx as _jsx } from "@emotion/react/jsx-runtime";
import { useState, useEffect } from 'react';
import { ConfigProvider } from './config-provider';
import { ThemeTokenProvider } from './theme-token-provider';
import { ThemeContext } from './contexts';
export const ThemeProvider = ({ children }) => {
    const [mode, setMode] = useState('light');
    useEffect(() => {
        const handleSwitchTheme = () => {
            const newMode = mode === 'light' ? 'dark' : 'light';
            if (newMode === 'dark') {
                document.body.classList.add('editor-theme_dark');
            }
            else {
                document.body.classList.remove('editor-theme_dark');
            }
            setMode(newMode);
        };
        const unsubscribe = window.electron.onSwitchTheme(handleSwitchTheme);
        return () => unsubscribe();
    }, [mode]);
    return (_jsx(ThemeContext.Provider, { value: mode, children: _jsx(ConfigProvider, { children: _jsx(ThemeTokenProvider, { children: children }) }) }));
};
