import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
import { Box, Text, Static } from "ink";
import { c } from "../theme.js";
import { ToolTimelineItem } from "./tool-timeline-item.js";
const MAX_TOOL_OUTPUT_PREVIEW = 200;
function ActivityItemRow({ item }) {
    switch (item.type) {
        case "user":
            return (_jsxs(Box, { children: [_jsxs(Text, { bold: true, children: [c.blue("You:"), " "] }), _jsx(Text, { children: item.content })] }));
        case "assistant":
            return (_jsxs(Box, { flexDirection: "column", children: [_jsxs(Text, { bold: true, children: [c.cyan("Agent:"), " "] }), _jsx(Text, { children: item.content })] }));
        case "thinking":
            return (_jsxs(Box, { flexDirection: "column", children: [_jsxs(Text, { bold: true, children: [c.magenta("Thinking:"), " "] }), _jsx(Text, { dimColor: true, children: item.content })] }));
        case "tool_call":
            return _jsx(ToolTimelineItem, { item: item });
        case "tool_result": {
            const preview = item.content.length > MAX_TOOL_OUTPUT_PREVIEW
                ? item.content.slice(0, MAX_TOOL_OUTPUT_PREVIEW) +
                    "\n[... truncated ...]"
                : item.content;
            return (_jsx(Box, { flexDirection: "column", paddingLeft: 2, children: _jsx(Text, { dimColor: true, children: preview }) }));
        }
        case "token_usage":
            return (_jsx(Box, { children: _jsxs(Text, { dimColor: true, children: ["tokens: ", item.inputTokens, " in, ", item.outputTokens, " out"] }) }));
        case "system":
            return (_jsx(Box, { children: _jsx(Text, { dimColor: true, children: item.content }) }));
        default:
            return _jsx(Box, {});
    }
}
export function ActivityPane({ items }) {
    const completedItems = items.length > 0 ? items.slice(0, -1) : [];
    const lastItem = items.length > 0 ? items[items.length - 1] : undefined;
    return (_jsxs(Box, { flexDirection: "column", children: [_jsx(Static, { items: completedItems, children: (item, index) => (_jsx(Box, { children: _jsx(ActivityItemRow, { item: item }) }, `item-${index}`)) }), lastItem && (_jsx(Box, { children: _jsx(ActivityItemRow, { item: lastItem }) }, "last-item"))] }));
}
