import { jsx as _jsx } from "react/jsx-runtime";
import { Box, Text } from "ink";
import { flattenCellText, truncateStartCells } from "./design/textLayout.js";
const DEFAULT_THINKING_PREVIEW_WIDTH = 120;
export function ThinkingMessage(props) {
    return (_jsx(Box, { flexDirection: "row", children: _jsx(Text, { dimColor: true, italic: true, wrap: "truncate", children: formatThinkingPreview(props.text, props.previewWidth) }) }));
}
export function formatThinkingPreview(text, width = DEFAULT_THINKING_PREVIEW_WIDTH) {
    const normalized = normalizeThinkingText(text);
    if (!normalized)
        return "thinking...";
    return truncateStartCells(normalized, width);
}
export function normalizeThinkingText(text) {
    const lines = text.split(/\r?\n/).map((line) => line.trim()).filter(Boolean);
    const doneLine = lines.find((line) => /thinking done/i.test(line));
    const body = flattenCellText(lines.filter((line) => line !== doneLine).join(" "))
        .replace(/^(thinking|reasoning)\s*:\s*/i, "");
    if (doneLine)
        return `${doneLine} - ${body}`;
    return body;
}
