import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
import React from "react";
import { Text, Box } from "ink";
import { useTheme } from "../theme/theme.js";
import { SPINNER_FRAMES, SPINNER_INTERVAL } from "../spinner-frames.js";
import { useFocusedAnimation, deriveFrame } from "./AnimationContext.js";
const ACCENT_COLOR = "#fbbf24"; // warning/amber
function formatTokenCount(n) {
    if (n >= 1000) {
        const k = n / 1000;
        return k >= 10 ? `${Math.round(k)}k` : `${k.toFixed(1)}k`;
    }
    return String(n);
}
export function CompactionSpinner({ staticDisplay = false, marginTop = 0, }) {
    const theme = useTheme();
    const { active: animationActive, tick } = useFocusedAnimation(!staticDisplay);
    const frame = animationActive ? deriveFrame(tick, SPINNER_INTERVAL, SPINNER_FRAMES.length) : 0;
    return (_jsx(Box, { paddingLeft: 1, marginTop: marginTop, children: _jsxs(Box, { borderStyle: "single", borderLeft: true, borderRight: false, borderTop: false, borderBottom: false, borderLeftColor: ACCENT_COLOR, paddingLeft: 2, children: [_jsxs(Text, { color: ACCENT_COLOR, children: [SPINNER_FRAMES[frame], " "] }), _jsx(Text, { color: theme.textMuted, italic: true, children: "Compacting conversation" }), _jsx(Text, { color: theme.textDim, children: "..." })] }) }));
}
export function CompactionDone({ originalCount, newCount, tokensBefore, tokensAfter, marginTop = 0, }) {
    const theme = useTheme();
    const reduction = tokensBefore > 0 ? Math.round((1 - tokensAfter / tokensBefore) * 100) : 0;
    return (_jsx(Box, { paddingLeft: 1, marginTop: marginTop, children: _jsxs(Box, { borderStyle: "single", borderLeft: true, borderRight: false, borderTop: false, borderBottom: false, borderLeftColor: ACCENT_COLOR, paddingLeft: 1, flexDirection: "column", children: [_jsxs(Box, { children: [_jsx(Text, { color: ACCENT_COLOR, children: "⟳ " }), _jsx(Text, { color: theme.textMuted, children: "Conversation compacted" })] }), _jsx(Box, { marginLeft: 2, children: _jsxs(Text, { color: theme.textDim, children: [originalCount, " \u2192 ", newCount, " messages \u00B7 ", formatTokenCount(tokensBefore), " \u2192", " ", formatTokenCount(tokensAfter), " tokens \u00B7 ", reduction, "% reduction"] }) })] }) }));
}
//# sourceMappingURL=CompactionNotice.js.map