import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { Box, Text } from "ink";
import { formatShellOutput } from "./ShellResultBlock.js";
import { ToolProgress } from "./ToolProgress.js";
import { flattenCellText, truncateCells } from "./design/textLayout.js";
export function BashModeProgress(props) {
    const model = bashModeProgressModel(props);
    const width = props.width ?? 96;
    return (_jsxs(Box, { flexDirection: "column", marginTop: 1, children: [_jsxs(Text, { children: [_jsx(Text, { color: "gray", children: "$ " }), _jsx(Text, { children: truncateCells(model.command, Math.max(12, width - 2)) })] }), _jsx(ToolProgress, { name: "run_command", status: "running", detail: model.detail }), _jsx(Text, { color: "gray", children: `${model.elapsedLabel} | ${model.totalLinesLabel}` }), model.outputLines.length > 0 ? (_jsx(Box, { flexDirection: "column", children: model.outputLines.map((line, index) => (_jsx(Text, { color: "gray", children: truncateCells(line || " ", Math.max(12, width)) }, `${index}:${line.slice(0, 16)}`))) })) : null] }));
}
export function bashModeProgressModel(input) {
    const command = flattenCellText(input.input).trim() || "(empty shell input)";
    const progress = input.progress ?? null;
    const output = input.verbose ? progress?.fullOutput || progress?.output || "" : progress?.output || "";
    return {
        command,
        detail: progress ? "shell command is still running" : "waiting for shell output",
        outputLines: output ? formatShellOutput(output, input.maxLines ?? 8) : [],
        elapsedLabel: typeof progress?.elapsedTimeSeconds === "number"
            ? `${Math.max(0, Math.floor(progress.elapsedTimeSeconds))}s`
            : "0s",
        totalLinesLabel: typeof progress?.totalLines === "number"
            ? `${Math.max(0, progress.totalLines)} lines`
            : "0 lines",
    };
}
