import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { Box, Text } from "ink";
import { StatusIcon } from "./design/StatusIcon.js";
import { toneColor } from "./design/terminalTheme.js";
export function buildTokenBudgetWarning(input) {
    if (!Number.isFinite(input.usedTokens) || !Number.isFinite(input.contextLimit) || input.contextLimit <= 0) {
        return null;
    }
    const usedRatio = Math.max(0, input.usedTokens / input.contextLimit);
    if (usedRatio < 0.75)
        return null;
    const usedPercent = Math.min(100, Math.round(usedRatio * 100));
    const remaining = Math.max(0, input.contextLimit - input.usedTokens);
    const critical = usedRatio >= 0.9;
    return {
        state: critical ? "error" : "warning",
        tone: critical ? "error" : "warning",
        title: `context ${usedPercent}% used`,
        detail: `${remaining} tokens remaining on ${input.model}`,
        recommendation: critical ? "compact before another large tool turn" : "prefer /cache plan before expanding context",
    };
}
export function TokenBudgetWarning(props) {
    const model = buildTokenBudgetWarning(props);
    if (!model)
        return null;
    return (_jsxs(Box, { flexDirection: "column", children: [_jsxs(Box, { flexDirection: "row", children: [_jsx(StatusIcon, { state: model.state, withSpace: true }), _jsx(Text, { color: toneColor(model.tone), children: model.title })] }), _jsx(Text, { color: "gray", children: model.detail }), _jsx(Text, { color: "gray", children: model.recommendation })] }));
}
