import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
import React, { useMemo } from "react";
import { Text, Box } from "ink";
import { ToolUseLoader } from "./ToolUseLoader.js";
import { Spinner } from "./Spinner.js";
import { useTheme } from "../theme/theme.js";
import { buildToolGroupSummary, } from "../tool-group-summary.js";
import { toolTonePalette } from "../transcript/tool-presentation.js";
const RESPONSE_LEFT_PADDING = 1;
// ── Components ───────────────────────────────────────────
function SummaryText({ segments, color }) {
    const theme = useTheme();
    return (_jsx(_Fragment, { children: segments.map((seg, i) => (_jsx(Text, { bold: seg.bold, color: seg.tone ? toolTonePalette(theme, seg.tone).primary : color, children: seg.text }, i))) }));
}
export function ToolGroupExecution({ tools, marginTop = 0, summaryRenderers, }) {
    const theme = useTheme();
    const allDone = tools.every((t) => t.status === "done");
    const hasError = tools.some((t) => t.isError);
    const status = allDone ? (hasError ? "error" : "done") : "running";
    const staticDisplay = status !== "running";
    const segments = useMemo(() => buildToolGroupSummary(tools, allDone, summaryRenderers), [tools, allDone, summaryRenderers]);
    const labelColor = status === "error" ? theme.error : status === "done" ? theme.success : theme.toolName;
    return (_jsxs(Box, { paddingLeft: RESPONSE_LEFT_PADDING, marginTop: marginTop, flexDirection: "row", children: [status === "running" ? (_jsx(Box, { width: 2, flexShrink: 0, children: _jsx(Spinner, { staticDisplay: staticDisplay }) })) : (_jsx(ToolUseLoader, { status: status })), _jsx(Box, { flexGrow: 1, flexShrink: 1, children: _jsx(Text, { wrap: "wrap", children: _jsx(SummaryText, { segments: segments, color: labelColor }) }) })] }));
}
//# sourceMappingURL=ToolGroupExecution.js.map