import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { useMemo } from 'react';
import { escapeAnsiCtrlCodes, sanitizeSensitiveText, } from '../utils/textUtils.js';
import { UserMessage, UserShellMessage, AssistantMessage, AssistantMessageContent, ThinkMessage, ThinkMessageContent, } from './messages/ConversationMessages.js';
import { ToolGroupMessage } from './messages/ToolGroupMessage.js';
import { CompressionMessage } from './messages/CompressionMessage.js';
import { SummaryMessage } from './messages/SummaryMessage.js';
import { InfoMessage, WarningMessage, ErrorMessage, RetryCountdownMessage, SuccessMessage, AwayRecapMessage, } from './messages/StatusMessages.js';
import { Box, Text } from 'ink';
import { theme } from '../semantic-colors.js';
import { MarkdownDisplay, } from '../utils/MarkdownDisplay.js';
import { AboutBox } from './AboutBox.js';
import { StatsDisplay } from './StatsDisplay.js';
import { ModelStatsDisplay } from './ModelStatsDisplay.js';
import { ToolStatsDisplay } from './ToolStatsDisplay.js';
import { SessionSummaryDisplay } from './SessionSummaryDisplay.js';
import { Help } from './Help.js';
import { ExtensionsList } from './views/ExtensionsList.js';
import { getMCPServerStatus } from '@hoptrendy/hopcode-core';
import { SkillsList } from './views/SkillsList.js';
import { ToolsList } from './views/ToolsList.js';
import { McpStatus } from './views/McpStatus.js';
import { ContextUsage } from './views/ContextUsage.js';
import { DoctorReport } from './views/DoctorReport.js';
import { ArenaAgentCard, ArenaSessionCard } from './arena/ArenaCards.js';
import { InsightProgressMessage } from './messages/InsightProgressMessage.js';
import { BtwMessage } from './messages/BtwMessage.js';
import { MemorySavedMessage } from './messages/MemorySavedMessage.js';
import { DiffStatsDisplay } from './messages/DiffStatsDisplay.js';
import { useCompactMode } from '../contexts/CompactModeContext.js';
const HistoryItemDisplayComponent = ({ item, availableTerminalHeight, terminalWidth, mainAreaWidth, isPending, commands, isFocused = true, activeShellPtyId, embeddedShellFocused, availableTerminalHeightGemini, compactLabel, summaryAbsorbed = false, sourceCopyIndexOffsets, }) => {
    const marginTop = item.type === 'gemini_content' || item.type === 'gemini_thought_content'
        ? 0
        : 1;
    const { compactMode } = useCompactMode();
    const itemForDisplay = useMemo(() => escapeAnsiCtrlCodes(item), [item]);
    const contentWidth = terminalWidth - 4;
    const boxWidth = mainAreaWidth || contentWidth;
    return (_jsxs(Box, { flexDirection: "column", marginTop: marginTop, marginLeft: 2, marginRight: 2, children: [itemForDisplay.type === 'user' && (_jsx(UserMessage, { text: itemForDisplay.text })), itemForDisplay.type === 'notification' && (_jsx(InfoMessage, { text: itemForDisplay.text })), itemForDisplay.type === 'user_shell' && (_jsx(UserShellMessage, { text: itemForDisplay.text })), itemForDisplay.type === 'gemini' && (_jsx(AssistantMessage, { text: itemForDisplay.text, isPending: isPending, availableTerminalHeight: availableTerminalHeightGemini ?? availableTerminalHeight, contentWidth: contentWidth, sourceCopyIndexOffsets: sourceCopyIndexOffsets })), itemForDisplay.type === 'gemini_content' && (_jsx(AssistantMessageContent, { text: itemForDisplay.text, isPending: isPending, availableTerminalHeight: availableTerminalHeightGemini ?? availableTerminalHeight, contentWidth: contentWidth, sourceCopyIndexOffsets: sourceCopyIndexOffsets })), !compactMode && itemForDisplay.type === 'gemini_thought' && (_jsx(ThinkMessage, { text: itemForDisplay.text, isPending: isPending, availableTerminalHeight: availableTerminalHeightGemini ?? availableTerminalHeight, contentWidth: contentWidth })), !compactMode && itemForDisplay.type === 'gemini_thought_content' && (_jsx(ThinkMessageContent, { text: itemForDisplay.text, isPending: isPending, availableTerminalHeight: availableTerminalHeightGemini ?? availableTerminalHeight, contentWidth: contentWidth })), itemForDisplay.type === 'info' && (_jsx(InfoMessage, { text: itemForDisplay.text, linkUrl: itemForDisplay.linkUrl, linkText: itemForDisplay.linkText })), itemForDisplay.type === 'success' && (_jsx(SuccessMessage, { text: itemForDisplay.text })), itemForDisplay.type === 'warning' && (_jsx(WarningMessage, { text: itemForDisplay.text })), itemForDisplay.type === 'error' && (_jsx(ErrorMessage, { text: itemForDisplay.text, hint: itemForDisplay.hint })), itemForDisplay.type === 'retry_countdown' && (_jsx(RetryCountdownMessage, { text: itemForDisplay.text })), itemForDisplay.type === 'about' && (_jsx(AboutBox, { ...itemForDisplay.systemInfo, width: boxWidth })), itemForDisplay.type === 'help' && commands && (_jsx(Help, { commands: commands, width: boxWidth })), itemForDisplay.type === 'stats' && (_jsx(StatsDisplay, { duration: itemForDisplay.duration, width: boxWidth })), itemForDisplay.type === 'diff_stats' && (_jsx(DiffStatsDisplay, { model: itemForDisplay.model })), itemForDisplay.type === 'model_stats' && (_jsx(ModelStatsDisplay, { width: boxWidth })), itemForDisplay.type === 'tool_stats' && (_jsx(ToolStatsDisplay, { width: boxWidth })), itemForDisplay.type === 'quit' && (_jsx(SessionSummaryDisplay, { duration: itemForDisplay.duration, width: boxWidth })), itemForDisplay.type === 'tool_group' && (_jsx(ToolGroupMessage, { toolCalls: itemForDisplay.tools, groupId: itemForDisplay.id, availableTerminalHeight: availableTerminalHeight, contentWidth: contentWidth, isFocused: isFocused, isPending: isPending, activeShellPtyId: activeShellPtyId, embeddedShellFocused: embeddedShellFocused, memoryWriteCount: itemForDisplay.memoryWriteCount, memoryReadCount: itemForDisplay.memoryReadCount, isUserInitiated: itemForDisplay.isUserInitiated, compactLabel: compactLabel })), itemForDisplay.type === 'tool_use_summary' &&
                (!compactMode || !summaryAbsorbed) && (_jsx(Box, { paddingLeft: 1, children: _jsxs(Text, { dimColor: true, children: ["\u25CF ", itemForDisplay.summary] }) })), itemForDisplay.type === 'compression' && (_jsx(CompressionMessage, { compression: itemForDisplay.compression })), itemForDisplay.type === 'summary' && (_jsx(SummaryMessage, { summary: itemForDisplay.summary })), itemForDisplay.type === 'extensions_list' && _jsx(ExtensionsList, {}), itemForDisplay.type === 'tools_list' && (_jsx(ToolsList, { contentWidth: contentWidth, tools: itemForDisplay.tools, showDescriptions: itemForDisplay.showDescriptions })), itemForDisplay.type === 'skills_list' && (_jsx(SkillsList, { skills: itemForDisplay.skills })), itemForDisplay.type === 'mcp_status' && (_jsx(McpStatus, { ...itemForDisplay, serverStatus: getMCPServerStatus })), itemForDisplay.type === 'context_usage' && (_jsx(ContextUsage, { modelName: itemForDisplay.modelName, totalTokens: itemForDisplay.totalTokens, contextWindowSize: itemForDisplay.contextWindowSize, breakdown: itemForDisplay.breakdown, builtinTools: itemForDisplay.builtinTools, mcpTools: itemForDisplay.mcpTools, memoryFiles: itemForDisplay.memoryFiles, skills: itemForDisplay.skills, isEstimated: itemForDisplay.isEstimated, showDetails: itemForDisplay.showDetails })), itemForDisplay.type === 'doctor' && (_jsx(DoctorReport, { checks: itemForDisplay.checks, summary: itemForDisplay.summary, width: boxWidth })), itemForDisplay.type === 'arena_agent_complete' && (_jsx(ArenaAgentCard, { agent: itemForDisplay.agent, width: boxWidth })), itemForDisplay.type === 'arena_session_complete' && (_jsx(ArenaSessionCard, { sessionStatus: itemForDisplay.sessionStatus, task: itemForDisplay.task, totalDurationMs: itemForDisplay.totalDurationMs, agents: itemForDisplay.agents, width: boxWidth })), itemForDisplay.type === 'insight_progress' && (_jsx(InsightProgressMessage, { progress: itemForDisplay.progress })), itemForDisplay.type === 'btw' && itemForDisplay.btw && (_jsx(BtwMessage, { btw: itemForDisplay.btw, containerWidth: contentWidth })), itemForDisplay.type === 'user_prompt_submit_blocked' && (_jsx(Box, { flexDirection: "column", children: _jsx(Text, { color: theme.status.warning, children: `✕ UserPromptSubmit operation blocked by hook:\n${itemForDisplay.reason}\n\nOriginal prompt: ${sanitizeSensitiveText(itemForDisplay.originalPrompt)}` }) })), itemForDisplay.type === 'stop_hook_loop' && (_jsx(InfoMessage, { text: `Ran ${itemForDisplay.stopHookCount} stop hooks\n  ⎿  Stop hook error: ${itemForDisplay.reasons[itemForDisplay.reasons.length - 1]}` })), itemForDisplay.type === 'stop_hook_system_message' && (_jsxs(Box, { flexDirection: "column", children: [_jsx(Text, { color: theme.text.primary, children: " \u23BF Stop says:" }), _jsx(Box, { marginLeft: 4, flexDirection: "column", children: _jsx(MarkdownDisplay, { text: itemForDisplay.message, isPending: false, contentWidth: contentWidth - 4 }) })] })), itemForDisplay.type === 'memory_saved' && (_jsx(MemorySavedMessage, { item: itemForDisplay })), itemForDisplay.type === 'away_recap' && (_jsx(AwayRecapMessage, { text: itemForDisplay.text })), itemForDisplay.type === 'history_context_note' && (_jsxs(Box, { borderStyle: "single", borderColor: theme.text.secondary, paddingX: 1, flexDirection: "column", children: [_jsxs(Text, { color: theme.text.secondary, bold: true, children: ["\u2191 Older history (items 0\u2013", itemForDisplay.windowTo - 1, " not shown)"] }), _jsx(Text, { color: theme.text.secondary, children: itemForDisplay.text }), _jsx(Text, { color: theme.text.secondary, dimColor: true, children: "Use /history older to navigate up \u00B7 /history newer to go back" })] }))] }, itemForDisplay.id));
};
// Export alias for backward compatibility
export { HistoryItemDisplayComponent as HistoryItemDisplay };
//# sourceMappingURL=HistoryItemDisplay.js.map