import { jsx as _jsx } from "react/jsx-runtime";
import React from "react";
import { UserMessage } from "../components/UserMessage.js";
import { AssistantMessage } from "../components/AssistantMessage.js";
import { IdealHookMessage } from "../components/IdealHookMessage.js";
import { CompactionDone, CompactionSpinner } from "../components/CompactionNotice.js";
import { Banner } from "../components/Banner.js";
import { isPanelReplacedToolItem, lastVisibleTranscriptItem } from "../app-items.js";
import { TranscriptItemFrame } from "./TranscriptItemFrame.js";
import { getTranscriptItemMarginTop } from "./spacing.js";
import { DurationRow, ErrorRow, QueuedRow, StepDoneRow, StylePackRow, UpdateNoticeRow, } from "./MiscRows.js";
import { presentInfo, presentModelTransition, presentPlanEvent, presentStopped, presentTask, presentThemeTransition, } from "./presentation.js";
import { StatusRow } from "./StatusRow.js";
import { SessionSummaryDisplay } from "../components/SessionSummary.js";
import { PlanModeLogo } from "../components/PlanModeLogo.js";
import { ServerToolDoneRow, ServerToolStartRow, SubAgentGroupRow, ToolDoneRow, ToolGroupRow, ToolStartRow, } from "./ToolRows.js";
export function renderTranscriptItem({ item, index, items, pendingHistoryFlushLastItem, historyLastItem, version, currentModel, currentProvider, displayedCwd, columns: _columns, theme: _theme, renderMarkdown, measuredLiveAreaRows, }) {
    // Skip panel-replaced tool rows (they render null) when looking back for the
    // spacing boundary — otherwise the assistant gets a blank separator above an
    // invisible row, leaving a phantom gap.
    const previousLiveItem = index > 0 ? lastVisibleTranscriptItem(items.slice(0, index)) : undefined;
    const transcriptMarginTop = getTranscriptItemMarginTop({
        item,
        previousLiveItem,
        lastPendingHistoryItem: pendingHistoryFlushLastItem,
        lastHistoryItem: historyLastItem,
    });
    const withTranscriptSpacing = (node) => (_jsx(TranscriptItemFrame, { marginTop: transcriptMarginTop, children: node }, `${item.id}-transcript-frame`));
    switch (item.kind) {
        case "tombstone":
            return null;
        case "banner":
            return (_jsx(Banner, { version: version, model: currentModel, provider: currentProvider, cwd: displayedCwd }, item.id));
        case "user":
            return withTranscriptSpacing(_jsx(UserMessage, { text: item.text, imageCount: item.imageCount, videoCount: item.videoCount, pasteInfo: item.pasteInfo }, item.id));
        case "style_pack":
            return withTranscriptSpacing(_jsx(StylePackRow, { item: item }));
        case "assistant": {
            // Reserve the rows that render OUTSIDE the markdown body so the whole
            // finalized assistant frame stays within `measuredLiveAreaRows`:
            //   1. the transcript top-spacing margin (`transcriptMarginTop`), and
            //   2. the collapsed thinking header (header line + `marginBottom:1`).
            // Keep THINKING_HEADER_ROWS in sync with ThinkingBlock's collapsed layout.
            const THINKING_HEADER_ROWS = 2;
            const assistantLiveBudget = Math.max(1, measuredLiveAreaRows - transcriptMarginTop - (item.thinking ? THINKING_HEADER_ROWS : 0));
            return withTranscriptSpacing(_jsx(AssistantMessage, { text: item.text, thinking: item.thinking, thinkingMs: item.thinkingMs, continuation: item.continuation, renderMarkdown: renderMarkdown, availableTerminalHeight: assistantLiveBudget }, item.id));
        }
        case "ideal_hook":
            return withTranscriptSpacing(_jsx(IdealHookMessage, { text: item.text, tone: item.tone }, item.id));
        case "tool_start":
        case "tool_done":
        case "tool_group":
        case "server_tool_start":
        case "server_tool_done":
            // Client and server tool activity now lives in the pinned LiveToolPanel
            // above the activity bar — suppress the in-transcript rows so they aren't
            // shown twice. Image-bearing results (read/screenshot) are the exception:
            // they keep their row so the inline preview still renders. Mirrors the
            // scrollback printer + fullscreen viewport, which use the same predicate.
            if (isPanelReplacedToolItem(item))
                return null;
            if (item.kind === "tool_start")
                return withTranscriptSpacing(_jsx(ToolStartRow, { item: item }));
            if (item.kind === "tool_done")
                return withTranscriptSpacing(_jsx(ToolDoneRow, { item: item }));
            if (item.kind === "tool_group")
                return withTranscriptSpacing(_jsx(ToolGroupRow, { item: item }));
            if (item.kind === "server_tool_start")
                return withTranscriptSpacing(_jsx(ServerToolStartRow, { item: item }));
            return withTranscriptSpacing(_jsx(ServerToolDoneRow, { item: item }));
        case "error":
            return withTranscriptSpacing(_jsx(ErrorRow, { item: item }));
        case "info":
            return withTranscriptSpacing(_jsx(StatusRow, { id: item.id, presentation: presentInfo(item) }));
        case "update_notice":
            return withTranscriptSpacing(_jsx(UpdateNoticeRow, { item: item }));
        case "plan_transition":
            if (item.active)
                return withTranscriptSpacing(_jsx(PlanModeLogo, {}, item.id));
            return null;
        case "task":
            return withTranscriptSpacing(_jsx(StatusRow, { id: item.id, presentation: presentTask(item) }));
        case "model_transition":
            return withTranscriptSpacing(_jsx(StatusRow, { id: item.id, presentation: presentModelTransition(item) }));
        case "theme_transition":
            return withTranscriptSpacing(_jsx(StatusRow, { id: item.id, presentation: presentThemeTransition(item) }));
        case "plan_event":
            return withTranscriptSpacing(_jsx(StatusRow, { id: item.id, presentation: presentPlanEvent(item) }));
        case "stopped":
            return withTranscriptSpacing(_jsx(StatusRow, { id: item.id, presentation: presentStopped(item) }));
        case "step_done":
            return withTranscriptSpacing(_jsx(StepDoneRow, { item: item }));
        case "queued":
            return withTranscriptSpacing(_jsx(QueuedRow, { item: item }));
        case "compacting":
            return withTranscriptSpacing(_jsx(CompactionSpinner, { staticDisplay: true }, item.id));
        case "compacted":
            return withTranscriptSpacing(_jsx(CompactionDone, { originalCount: item.originalCount, newCount: item.newCount, tokensBefore: item.tokensBefore, tokensAfter: item.tokensAfter }, item.id));
        case "duration":
            return withTranscriptSpacing(_jsx(DurationRow, { item: item }));
        case "session_summary":
            return withTranscriptSpacing(_jsx(SessionSummaryDisplay, { summary: item.summary }));
        case "subagent_group":
            return withTranscriptSpacing(_jsx(SubAgentGroupRow, { item: item }));
    }
}
//# sourceMappingURL=TranscriptRenderer.js.map