import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { Box, Text } from "ink";
import { ToolProgress } from "./ToolProgress.js";
import { flattenCellText, truncateCells } from "./design/textLayout.js";
const DEFAULT_TOOL_START_DETAIL_WIDTH = 120;
export function ToolStartMessage(props) {
    const info = parseToolStartText(props.text, props.detailWidth);
    return (_jsxs(Box, { flexDirection: "column", children: [_jsx(ToolProgress, { name: info.name, status: "running", detail: info.detail }), _jsx(Text, { dimColor: true, children: "waiting for result" })] }));
}
export function parseToolStartText(text, detailWidth = DEFAULT_TOOL_START_DETAIL_WIDTH) {
    const normalized = flattenCellText(text);
    const match = /^(?<name>[A-Za-z0-9_.:-]+)\s+started(?:\s+(?<detail>.*))?$/i.exec(normalized);
    if (!match?.groups) {
        return { name: "tool", detail: truncateOptional(normalized, detailWidth) };
    }
    const detail = truncateOptional(match.groups.detail ?? "", detailWidth);
    return { name: match.groups.name, detail };
}
function truncateOptional(value, width) {
    const trimmed = value.trim();
    if (!trimmed)
        return undefined;
    return truncateCells(trimmed, width);
}
