import { jsx as _jsx } from "react/jsx-runtime";
/**
 * @license
 * Copyright 2025 Vybestack LLC
 * SPDX-License-Identifier: Apache-2.0
 */
import { useReducer } from 'react';
import { KeypressProvider } from './contexts/KeypressContext.js';
import { MouseProvider } from './contexts/MouseContext.js';
import { SessionStatsProvider } from './contexts/SessionContext.js';
import { VimModeProvider } from './contexts/VimModeContext.js';
import { ToolCallProvider } from './contexts/ToolCallProvider.js';
import { TodoProvider } from './contexts/TodoProvider.js';
import { RuntimeContextProvider } from './contexts/RuntimeContext.js';
import { OverflowProvider } from './contexts/OverflowContext.js';
import { AppDispatchProvider } from './contexts/AppDispatchContext.js';
import { ScrollProvider } from './contexts/ScrollProvider.js';
import { useKittyKeyboardProtocol } from './hooks/useKittyKeyboardProtocol.js';
import { inkRenderOptions } from './inkRenderOptions.js';
import { isMouseEventsEnabled } from './mouseEventsEnabled.js';
import { appReducer, initialAppState } from './reducers/appReducer.js';
import { AppContainer } from './AppContainer.js';
/**
 * AppWrapper is the main entry point for the CLI UI.
 * It sets up the provider stack that wraps the AppContainer.
 *
 * Provider stack (outermost to innermost):
 * - KeypressProvider: Terminal keypress handling with Kitty/Vim support
 * - SessionStatsProvider: Session statistics tracking
 * - VimModeProvider: Vim mode state management
 * - ToolCallProvider: Tool call tracking
 * - TodoProvider: Todo list management
 * - RuntimeContextProvider: Runtime API access
 * - OverflowProvider: Overflow detection for UI
 * - AppDispatchProvider: App state dispatch
 * - AppContainer: Main UI container with UIState/UIActions contexts
 */
export const AppWrapper = (props) => {
    const kittyProtocolStatus = useKittyKeyboardProtocol();
    const renderOptions = inkRenderOptions(props.config, props.settings);
    const mouseEventsEnabled = isMouseEventsEnabled(renderOptions, props.settings);
    return (_jsx(KeypressProvider, { kittyProtocolEnabled: kittyProtocolStatus.enabled, config: props.config, debugKeystrokeLogging: props.settings.merged.debugKeystrokeLogging, mouseEventsEnabled: mouseEventsEnabled, children: _jsx(MouseProvider, { mouseEventsEnabled: mouseEventsEnabled, debugKeystrokeLogging: props.settings.merged.debugKeystrokeLogging, children: _jsx(ScrollProvider, { children: _jsx(SessionStatsProvider, { children: _jsx(VimModeProvider, { settings: props.settings, children: _jsx(ToolCallProvider, { sessionId: props.config.getSessionId(), children: _jsx(TodoProvider, { sessionId: props.config.getSessionId(), children: _jsx(RuntimeContextProvider, { children: _jsx(OverflowProvider, { children: _jsx(AppWithState, { ...props }) }) }) }) }) }) }) }) }) }));
};
/**
 * AppWithState manages the app reducer state and wraps AppContainer.
 */
const AppWithState = (props) => {
    const [appState, appDispatch] = useReducer(appReducer, initialAppState);
    return (_jsx(AppDispatchProvider, { value: appDispatch, children: _jsx(AppContainer, { ...props, appState: appState, appDispatch: appDispatch }) }));
};
// Re-export for backwards compatibility
export { AppContainer } from './AppContainer.js';
//# sourceMappingURL=App.js.map