import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import React from "react";
import { Text, Box } from "ink";
import { useTheme } from "../theme/theme.js";
import { Spinner } from "./Spinner.js";
import { ToolUseLoader } from "./ToolUseLoader.js";
import { MessageResponse } from "./MessageResponse.js";
import { useTerminalSize } from "../hooks/useTerminalSize.js";
import { toolNameColor } from "../transcript/tool-presentation.js";
const RESPONSE_LEFT_PADDING = 1;
// ToolUseLoader minWidth={2} = 2 chars
const HEADER_PREFIX = 2;
export function ServerToolExecution(props) {
    const theme = useTheme();
    const { columns } = useTerminalSize();
    const { label, detail } = getHeader(props.name, props.input);
    const staticDisplay = props.status === "running" ? false : true;
    const headerContentWidth = Math.max(10, columns - HEADER_PREFIX);
    const headerContent = (labelColor) => (_jsxs(Text, { wrap: "wrap", children: [_jsx(Text, { bold: true, color: labelColor, children: label }), detail && (_jsxs(Text, { color: theme.text, children: ["(", _jsx(Text, { color: theme.textDim, children: '"' }), detail, _jsx(Text, { color: theme.textDim, children: '"' }), ")"] }))] }));
    if (props.status === "running") {
        return (_jsxs(Box, { flexDirection: "column", paddingLeft: RESPONSE_LEFT_PADDING, marginTop: props.marginTop ?? 0, children: [_jsxs(Box, { flexDirection: "row", children: [_jsx(Box, { width: HEADER_PREFIX, flexShrink: 0, children: _jsx(Spinner, { staticDisplay: staticDisplay }) }), _jsx(Box, { flexGrow: 1, width: headerContentWidth, children: headerContent(toolNameColor(theme, props.name)) })] }), _jsx(MessageResponse, { children: _jsx(Text, { color: theme.textDim, wrap: "wrap", children: "Searching..." }) })] }));
    }
    const isAborted = props.resultType === "aborted";
    const duration = Math.round(props.durationMs / 1000);
    return (_jsxs(Box, { flexDirection: "column", paddingLeft: RESPONSE_LEFT_PADDING, marginTop: props.marginTop ?? 0, children: [_jsxs(Box, { flexDirection: "row", children: [_jsx(ToolUseLoader, { status: isAborted ? "error" : "done" }), _jsx(Box, { flexGrow: 1, width: headerContentWidth, children: headerContent(isAborted ? theme.error : toolNameColor(theme, props.name)) })] }), _jsx(MessageResponse, { children: _jsx(Text, { color: theme.textDim, wrap: "wrap", children: isAborted ? "Stopped." : `Did 1 search in ${duration}s` }) })] }));
}
function getHeader(name, input) {
    const inp = (input ?? {});
    if (name === "web_search") {
        const query = String(inp.query ?? "");
        const trunc = query.length > 60 ? query.slice(0, 57) + "…" : query;
        return { label: "Web Search", detail: trunc };
    }
    return { label: name, detail: "" };
}
//# sourceMappingURL=ServerToolExecution.js.map