import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { Box, Text } from "ink";
import { ToolUseLoader } from "./ToolUseLoader.js";
import { toneColor } from "./design/terminalTheme.js";
import { flattenCellText, truncateCells } from "./design/textLayout.js";
export function ToolProgress(props) {
    const model = toolProgressModel(props);
    return (_jsxs(Box, { flexDirection: "row", children: [_jsx(ToolUseLoader, { status: model.status }), _jsxs(Text, { color: toneColor(model.tone), children: [model.statusLabel, " "] }), _jsx(Text, { children: model.name }), model.detail ? _jsx(Text, { dimColor: true, children: ` - ${model.detail}` }) : null] }));
}
export function toolProgressModel(props) {
    return {
        name: flattenCellText(props.name).trim() || "tool",
        status: props.status,
        statusLabel: toolProgressStatusLabel(props.status),
        tone: toolProgressTone(props.status),
        detail: normalizeToolProgressDetail(props.detail, props.detailWidth ?? 96),
    };
}
export function toolProgressStatusLabel(status) {
    if (status === "succeeded")
        return "done";
    if (status === "failed")
        return "failed";
    if (status === "queued")
        return "queued";
    return "running";
}
export function toolProgressTone(status) {
    if (status === "failed")
        return "error";
    if (status === "succeeded")
        return "success";
    if (status === "queued")
        return "muted";
    return "warning";
}
function normalizeToolProgressDetail(value, width) {
    const normalized = flattenCellText(value ?? "").trim();
    if (!normalized)
        return undefined;
    return truncateCells(normalized, width);
}
