import { buildSection, buildToolHeaderLine, inlineText, renderToolOutput, renderToolUiCompactText, renderToolUiTextLines, } from "./tool_output.js";
export function buildBashRunningView(theme, command, headerTarget) {
    const { palette, text } = theme;
    const runningColor = (s) => palette.actionRunning(s);
    const commandInline = inlineText(headerTarget);
    const header = buildToolHeaderLine({
        bulletStyle: runningColor,
        bullet: "⏵",
        label: "running",
        labelStyle: palette.textMuted,
        accent: commandInline,
        accentStyle: palette.brandAccent,
    });
    return {
        borderColor: runningColor,
        expanded: { title: runningColor(text.bold(`$ ${command}`)) },
        compact: { header },
    };
}
export function buildBashExecutionView(theme, command, exitCode, uiText, labelOverride, headerTarget) {
    const { palette } = theme;
    const successColor = (s) => palette.actionSuccess(s);
    const errorColor = (s) => palette.actionError(s);
    const successBullet = (s) => palette.actionSuccess(s);
    const isSuccess = exitCode === 0;
    const resultColor = isSuccess ? successColor : errorColor;
    const commandInline = inlineText(headerTarget);
    const header = buildToolHeaderLine({
        bulletStyle: isSuccess ? successBullet : errorColor,
        bullet: isSuccess ? "✓" : "✗",
        label: labelOverride ?? "ran",
        labelStyle: palette.textMuted,
        accent: commandInline,
        accentStyle: palette.brandAccent,
    });
    const compactText = renderToolUiCompactText({
        uiText,
        theme,
        previewStyle: palette.textDim,
        statusStyle: palette.textMuted,
    });
    const fullStyle = palette.actionOutput;
    const fullText = renderToolUiTextLines({
        uiText,
        kind: "full",
        theme,
        baseStyle: fullStyle,
    });
    const sections = fullText ? [fullText] : [];
    return {
        borderColor: resultColor,
        expanded: {
            title: resultColor(theme.text.bold(`$ ${command}`)),
            sections,
        },
        compact: {
            header,
            extraText: compactText,
        },
    };
}
export function buildBashBlockedView(theme, command, reason, headerTarget) {
    const { palette, text } = theme;
    const errorColor = (s) => palette.actionError(s);
    const msg = reason.trim();
    const sections = buildSection(msg ? [errorColor(msg)] : []);
    const commandInline = inlineText(headerTarget);
    const why = inlineText(reason);
    const header = buildToolHeaderLine({
        bulletStyle: errorColor,
        bullet: "✗",
        label: "bash blocked",
        labelStyle: palette.textMuted,
        accent: commandInline,
        accentStyle: palette.brandAccent,
    });
    return {
        borderColor: errorColor,
        expanded: {
            title: errorColor(text.bold(`$ ${command}`)),
            sections: sections ? [sections] : [],
        },
        compact: {
            header,
            extraText: why ? `    ${errorColor(why)}` : undefined,
        },
    };
}
export function buildBashAbortedView(theme, command, reason, headerTarget) {
    const { palette, text } = theme;
    const warnColor = (s) => palette.statusWarn(s);
    const msg = reason.trim();
    const sections = buildSection(msg ? [warnColor(msg)] : []);
    const commandInline = inlineText(headerTarget);
    const why = inlineText(reason);
    const details = why ? palette.textMuted(`(${why})`) : undefined;
    const header = buildToolHeaderLine({
        bulletStyle: warnColor,
        bullet: "✗",
        label: inlineText(reason) || "aborted",
        labelStyle: palette.textMuted,
        accent: commandInline,
        accentStyle: palette.brandAccent,
    });
    return {
        borderColor: warnColor,
        expanded: {
            title: warnColor(text.bold(`$ ${command}`)),
            sections: sections ? [sections] : [],
        },
        compact: {
            header,
            extraText: details ? `    ${details}` : undefined,
        },
    };
}
export function renderBashRunning(theme, command, compact, headerTarget) {
    return renderToolOutput(buildBashRunningView(theme, command, headerTarget), compact);
}
export function renderBashExecution(theme, command, exitCode, uiText, compact, headerTarget) {
    return renderToolOutput(buildBashExecutionView(theme, command, exitCode, uiText, undefined, headerTarget), compact);
}
export function renderBashBlocked(theme, command, reason, compact, headerTarget) {
    return renderToolOutput(buildBashBlockedView(theme, command, reason, headerTarget), compact);
}
export function renderBashAborted(theme, command, reason, compact, headerTarget) {
    return renderToolOutput(buildBashAbortedView(theme, command, reason, headerTarget), compact);
}
//# sourceMappingURL=bash_execution.js.map