import { jsx as _jsx } from "react/jsx-runtime";
import React, { memo, useMemo } from "react";
import { Box } from "ink";
import { stripDoneMarkers } from "../../utils/plan-steps.js";
import { AssistantMessage } from "./AssistantMessage.js";
function estimateWrappedLineCount(text, width) {
    return text
        .split("\n")
        .reduce((count, line) => count + Math.max(1, Math.ceil(line.length / width)), 0);
}
export function getStreamingTextPreview(text, width) {
    const safeWidth = Math.max(10, width);
    if (estimateWrappedLineCount(text, safeWidth) <= 12) {
        return { text, isTruncated: false };
    }
    return { text: "", isTruncated: true };
}
export const StreamingArea = memo(function StreamingArea({ isRunning, streamingText, streamingThinking, showThinking = false, thinkingMs, reserveSpacing = false, renderMarkdown = true, availableTerminalHeight, assistantMarginTop = 0, continuation = false, }) {
    const displayText = useMemo(() => (streamingText ? stripDoneMarkers(streamingText) : ""), [streamingText]);
    const trimmedDisplay = displayText.trim();
    const hasThinking = showThinking && !!streamingThinking;
    if (!trimmedDisplay && !hasThinking) {
        return reserveSpacing ? _jsx(Box, { height: 1 }) : null;
    }
    if (!isRunning && !trimmedDisplay)
        return null;
    return (_jsx(AssistantMessage, { text: trimmedDisplay, thinking: streamingThinking, thinkingMs: thinkingMs, showThinking: showThinking, streaming: true, renderMarkdown: renderMarkdown, availableTerminalHeight: availableTerminalHeight, marginTop: assistantMarginTop, continuation: continuation }));
});
//# sourceMappingURL=StreamingArea.js.map