import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
import { useMemo } from 'react';
import { Box, Text } from 'ink';
import { theme } from '../../semantic-colors.js';
import { normalizeEscapedNewlines } from '../../utils/textUtils.js';
const THINKING_LEFT_PADDING = 1;
function normalizeThoughtLines(thought) {
    const subject = normalizeEscapedNewlines(thought.subject).trim();
    const description = normalizeEscapedNewlines(thought.description).trim();
    if (!subject && !description) {
        return [];
    }
    if (!subject) {
        return description.split('\n');
    }
    if (!description) {
        return [subject];
    }
    const bodyLines = description.split('\n');
    return [subject, ...bodyLines];
}
/**
 * Renders a model's thought as a distinct bubble.
 * Leverages Ink layout for wrapping and borders.
 */
export const ThinkingMessage = ({ thought, terminalWidth, isFirstThinking, }) => {
    const fullLines = useMemo(() => normalizeThoughtLines(thought), [thought]);
    if (fullLines.length === 0) {
        return null;
    }
    return (_jsxs(Box, { width: terminalWidth, flexDirection: "column", children: [isFirstThinking && (_jsxs(Text, { color: theme.text.primary, italic: true, children: [' ', "Thinking...", ' '] })), _jsxs(Box, { marginLeft: THINKING_LEFT_PADDING, paddingLeft: 1, borderStyle: "single", borderLeft: true, borderRight: false, borderTop: false, borderBottom: false, borderColor: theme.text.secondary, flexDirection: "column", children: [_jsx(Text, { children: " " }), fullLines.length > 0 && (_jsx(Text, { color: theme.text.primary, bold: true, italic: true, children: fullLines[0] })), fullLines.slice(1).map((line, index) => (_jsx(Text, { color: theme.text.secondary, italic: true, children: line }, `body-line-${index}`)))] })] }));
};
//# sourceMappingURL=ThinkingMessage.js.map