import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { Box, useInput } from 'ink';
import { ChatHistory } from '../../app/components/chat-history.js';
import { ChatInput } from '../../app/components/chat-input.js';
import { ModalSelectors } from '../../app/components/modal-selectors.js';
import { FileExplorer } from '../../components/file-explorer.js';
import { IdeSelector } from '../../components/ide-selector.js';
import { displayCompactCountsSummary } from '../../utils/tool-result-display.js';
/**
 * The full interactive render tree: chat history + transient modals + chat
 * input. Lifted out of `App.tsx` so the orchestrator can stay focused on
 * hook composition rather than JSX wiring. Every interactive surface that
 * the user can see during a normal session lives here.
 */
export function InteractiveApp({ appState, chatHandler, modeHandlers, appHandlers, vscodeServer, staticComponents, liveComponent, pendingSubagentApproval, handleSubagentToolApproval, pendingToolConfirmation, handleToolConfirmation, handleQuestionAnswer, handleUserSubmit, handleIdeSelect, }) {
    const handleToggleCompactDisplay = () => {
        const expanding = appState.compactToolDisplay;
        appState.setCompactToolDisplay(!expanding);
        // When expanding, flush accumulated counts to static
        if (expanding) {
            const counts = appState.compactToolCountsRef.current;
            if (Object.keys(counts).length > 0) {
                displayCompactCountsSummary(counts, appState.addToChatQueue);
                appState.compactToolCountsRef.current = {};
                appState.setCompactToolCounts(null);
            }
        }
    };
    const handleToggleReasoningExpanded = () => {
        appState.setReasoningExpanded(!appState.reasoningExpanded);
    };
    const showModalSelectors = (appState.activeMode !== null &&
        appState.activeMode !== 'explorer' &&
        appState.activeMode !== 'ideSelection') ||
        appState.isSettingsMode;
    // Whether there is in-flight work that Escape should immediately cancel.
    // Decision states (tool confirmation, question prompt, subagent approval)
    // own their own Escape handling and must NOT be hijacked into a generation
    // abort, so they are excluded here.
    const cancellable = !appState.isToolConfirmationMode &&
        !appState.isQuestionMode &&
        pendingSubagentApproval === null &&
        pendingToolConfirmation === null &&
        (appState.isCancelling ||
            chatHandler.isGenerating ||
            appState.isToolExecuting ||
            appState.abortController !== null);
    // Single, always-mounted authority for Escape -> cancel. Because this lives
    // at the section level (never swapped out like the ChatInput children), it
    // fires on the FIRST press no matter what is running: an LLM message, a
    // regular tool behind ToolExecutionIndicator, a bash command, or a subagent.
    // `isActive` keeps it dormant when there's nothing to cancel, so idle Escape
    // still drives the clear-input behaviour in UserInput.
    useInput((_input, key) => {
        if (key.escape) {
            appHandlers.handleCancel();
        }
    }, { isActive: cancellable });
    return (_jsxs(Box, { flexDirection: "column", padding: 1, width: "100%", children: [_jsx(ChatHistory, { startChat: appState.startChat, staticComponents: staticComponents, queuedComponents: appState.chatComponents, liveComponent: liveComponent }), appState.isExplorerMode && (_jsx(Box, { marginLeft: -1, flexDirection: "column", children: _jsx(FileExplorer, { onClose: modeHandlers.handleExplorerCancel }) })), appState.isIdeSelectionMode && (_jsx(Box, { marginLeft: -1, flexDirection: "column", children: _jsx(IdeSelector, { onSelect: handleIdeSelect, onCancel: modeHandlers.handleIdeSelectionCancel }) })), showModalSelectors && (_jsx(Box, { marginLeft: -1, flexDirection: "column", children: _jsx(ModalSelectors, { activeMode: appState.activeMode, isSettingsMode: appState.isSettingsMode, showAllSessions: appState.showAllSessions, currentModel: appState.currentModel, currentProvider: appState.currentProvider, checkpointLoadData: appState.checkpointLoadData, onModelSelect: modeHandlers.handleModelSelect, onModelSelectionCancel: modeHandlers.handleModelSelectionCancel, onModelDatabaseCancel: modeHandlers.handleModelDatabaseCancel, onConfigWizardComplete: modeHandlers.handleConfigWizardComplete, onConfigWizardCancel: modeHandlers.handleConfigWizardCancel, onMcpWizardComplete: modeHandlers.handleMcpWizardComplete, onMcpWizardCancel: modeHandlers.handleMcpWizardCancel, onSettingsCancel: modeHandlers.handleSettingsCancel, tuneConfig: appState.tune, onTuneSelect: modeHandlers.handleTuneSelect, onTuneCancel: modeHandlers.handleTuneCancel, onCheckpointSelect: appHandlers.handleCheckpointSelect, onCheckpointCancel: appHandlers.handleCheckpointCancel, onSessionSelect: sessionId => void appHandlers.handleSessionSelect(sessionId), onSessionCancel: appHandlers.handleSessionCancel }) })), appState.startChat &&
                appState.activeMode === null &&
                !appState.isSettingsMode && (_jsx(ChatInput, { isCancelling: appState.isCancelling, isToolExecuting: appState.isToolExecuting, isQuestionMode: appState.isQuestionMode, pendingToolCalls: appState.pendingToolCalls, currentToolIndex: appState.currentToolIndex, pendingQuestion: appState.pendingQuestion, onQuestionAnswer: handleQuestionAnswer, mcpInitialized: appState.mcpInitialized, client: appState.client, customCommands: Array.from(appState.customCommandCache.keys()), inputDisabled: chatHandler.isGenerating || appState.isToolExecuting, isBusy: cancellable, developmentMode: appState.developmentMode, contextPercentUsed: appState.contextPercentUsed, contextSource: appState.contextSource, sessionName: appState.sessionName || undefined, compactToolCounts: appState.compactToolCounts, compactToolDisplay: appState.compactToolDisplay, liveTaskList: appState.liveTaskList, onToggleCompactDisplay: handleToggleCompactDisplay, pendingSubagentApproval: pendingSubagentApproval, onSubagentToolApproval: handleSubagentToolApproval, pendingToolConfirmation: pendingToolConfirmation, onToolConfirmation: handleToolConfirmation, onSubmit: handleUserSubmit, activeEditor: vscodeServer.activeEditor, onDismissActiveEditor: vscodeServer.dismissActiveEditor, onToggleMode: appHandlers.handleToggleDevelopmentMode, onToggleReasoningExpanded: handleToggleReasoningExpanded, tune: appState.tune, currentModel: appState.currentModel }))] }));
}
//# sourceMappingURL=interactive-app.js.map