import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { Box, Text } from "ink";
import { InterruptedByUser } from "./InterruptedByUser.js";
import { Markdown } from "./Markdown.js";
import { MessageResponse } from "./MessageResponse.js";
export function AssistantTextMessage(props) {
    const kind = classifyAssistantText(props.text);
    const text = formatAssistantText(props.text);
    if (kind === "empty")
        return _jsx(Text, { dimColor: true, children: " " });
    if (kind === "interrupted") {
        return (_jsx(MessageResponse, { tone: "warning", height: 1, children: _jsx(InterruptedByUser, {}) }));
    }
    if (kind === "context-limit") {
        return (_jsx(MessageResponse, { tone: "warning", children: _jsxs(Box, { flexDirection: "column", children: [_jsx(Text, { color: "yellow", children: "context limit reached" }), _jsx(Markdown, { dimColor: true, children: text })] }) }));
    }
    if (kind === "provider-error") {
        return (_jsx(MessageResponse, { tone: "error", children: _jsxs(Box, { flexDirection: "column", children: [_jsx(Text, { color: "red", children: "provider error" }), _jsx(Markdown, { dimColor: true, children: text })] }) }));
    }
    return _jsx(Markdown, { children: text });
}
export function classifyAssistantText(text) {
    const normalized = formatAssistantText(text);
    if (!normalized)
        return "empty";
    if (/^(interrupted|aborted|cancelled by user)/i.test(normalized))
        return "interrupted";
    if (/\b(context limit|context window|prompt too long|max(?:imum)? tokens?)\b/i.test(normalized)) {
        return "context-limit";
    }
    if (/^(api error|provider error|deepseek error|error:|failed\b)/i.test(normalized)) {
        return "provider-error";
    }
    return "normal";
}
export function formatAssistantText(text) {
    return (text || "").trim();
}
