import { buildBlockedToolView, buildToolHeaderLine, inlineText, renderToolOutput, renderToolUiCompactText, renderToolUiTextLines, } from "./tool_output.js";
function formatRange(startLine, endLine) {
    if (endLine === undefined) {
        return `${startLine}-EOF`;
    }
    return `${startLine}-${endLine}`;
}
export function buildReadSuccessView(theme, path, startLine, endLine, uiText, headerTarget) {
    const { palette, text } = theme;
    const readColor = (s) => palette.actionSuccess(s);
    const successBullet = (s) => palette.actionSuccess(s);
    const expandedSections = [];
    const fullText = renderToolUiTextLines({
        uiText,
        kind: "full",
        theme,
        baseStyle: palette.actionOutput,
    });
    if (fullText) {
        expandedSections.push(fullText);
    }
    const pathInline = inlineText(headerTarget);
    const header = buildToolHeaderLine({
        bulletStyle: successBullet,
        bullet: "✓",
        label: "read",
        labelStyle: palette.textMuted,
        accent: pathInline,
        accentStyle: palette.brandAccent,
    });
    const compactText = renderToolUiCompactText({
        uiText,
        theme,
        previewStyle: palette.textDim,
        statusStyle: palette.textMuted,
    });
    return {
        borderColor: readColor,
        expanded: {
            title: readColor(text.bold(`read ${path} (${formatRange(startLine, endLine)})`)),
            sections: expandedSections,
        },
        compact: {
            header,
            extraText: compactText,
        },
    };
}
export function buildReadBlockedView(theme, path, reason, headerTarget) {
    return buildBlockedToolView({
        theme,
        label: "read blocked",
        title: `read ${path}`,
        accent: headerTarget,
        reason,
    });
}
export function buildListSuccessView(theme, path, uiText, headerTarget) {
    const { palette, text } = theme;
    const listColor = (s) => palette.actionSuccess(s);
    const successBullet = (s) => palette.actionSuccess(s);
    const expandedSections = [];
    const fullText = renderToolUiTextLines({
        uiText,
        kind: "full",
        theme,
        baseStyle: palette.actionOutput,
    });
    if (fullText) {
        expandedSections.push(fullText);
    }
    const pathInline = inlineText(headerTarget);
    const header = buildToolHeaderLine({
        bulletStyle: successBullet,
        bullet: "✓",
        label: "listed",
        labelStyle: palette.textMuted,
        accent: pathInline,
        accentStyle: palette.brandAccent,
    });
    const compactText = renderToolUiCompactText({
        uiText,
        theme,
        previewStyle: palette.textDim,
        statusStyle: palette.textMuted,
    });
    return {
        borderColor: listColor,
        expanded: {
            title: listColor(text.bold(`list ${path}`)),
            sections: expandedSections,
        },
        compact: {
            header,
            extraText: compactText,
        },
    };
}
export function buildListBlockedView(theme, path, reason, headerTarget) {
    return buildBlockedToolView({
        theme,
        label: "list blocked",
        title: `list ${path}`,
        accent: headerTarget,
        reason,
    });
}
export function buildGrepRunningView(theme, pattern, headerTarget) {
    const { palette, text } = theme;
    const runningColor = (s) => palette.actionRunning(s);
    const patternInline = inlineText(headerTarget);
    const header = buildToolHeaderLine({
        bulletStyle: runningColor,
        bullet: "⏵",
        label: "grep (running)",
        labelStyle: palette.textMuted,
        accent: patternInline,
        accentStyle: palette.brandAccent,
    });
    return {
        borderColor: runningColor,
        expanded: { title: runningColor(text.bold(`grep ${pattern}`)) },
        compact: { header },
    };
}
export function buildGrepFinishedView(theme, pattern, status, uiText, headerTarget) {
    const { palette, text } = theme;
    const grepColor = (s) => palette.actionSuccess(s);
    const errorColor = (s) => palette.actionError(s);
    const successBullet = (s) => palette.actionSuccess(s);
    const isSuccess = status === "success";
    const borderColor = isSuccess ? grepColor : errorColor;
    const expandedSections = [];
    const fullStyle = isSuccess ? palette.actionOutput : palette.actionError;
    const fullText = renderToolUiTextLines({
        uiText,
        kind: "full",
        theme,
        baseStyle: fullStyle,
    });
    if (fullText) {
        expandedSections.push(fullText);
    }
    const patternInline = inlineText(headerTarget);
    const header = buildToolHeaderLine({
        bulletStyle: isSuccess ? successBullet : errorColor,
        bullet: isSuccess ? "✓" : "✗",
        label: "grep",
        labelStyle: palette.textMuted,
        accent: patternInline,
        accentStyle: palette.brandAccent,
    });
    const previewStyle = isSuccess ? palette.textDim : palette.actionError;
    const statusStyle = isSuccess ? palette.textMuted : palette.actionError;
    const extraText = renderToolUiCompactText({
        uiText,
        theme,
        previewStyle,
        statusStyle,
    });
    return {
        borderColor,
        expanded: {
            title: borderColor(text.bold(`grep ${pattern}`)),
            sections: expandedSections,
        },
        compact: {
            header,
            extraText,
        },
    };
}
export function buildGrepBlockedView(theme, pattern, reason, headerTarget) {
    return buildBlockedToolView({
        theme,
        label: "grep blocked",
        title: `grep ${pattern}`,
        accent: headerTarget,
        reason,
    });
}
export function renderReadSuccess(theme, path, startLine, endLine, uiText, compact, headerTarget) {
    return renderToolOutput(buildReadSuccessView(theme, path, startLine, endLine, uiText, headerTarget), compact);
}
export function renderReadBlocked(theme, path, reason, compact, headerTarget) {
    return renderToolOutput(buildReadBlockedView(theme, path, reason, headerTarget), compact);
}
export function renderListSuccess(theme, path, uiText, compact, headerTarget) {
    return renderToolOutput(buildListSuccessView(theme, path, uiText, headerTarget), compact);
}
export function renderListBlocked(theme, path, reason, compact, headerTarget) {
    return renderToolOutput(buildListBlockedView(theme, path, reason, headerTarget), compact);
}
export function renderGrepRunning(theme, pattern, compact, headerTarget) {
    return renderToolOutput(buildGrepRunningView(theme, pattern, headerTarget), compact);
}
export function renderGrepFinished(theme, pattern, status, uiText, compact, headerTarget) {
    return renderToolOutput(buildGrepFinishedView(theme, pattern, status, uiText, headerTarget), compact);
}
export function renderGrepBlocked(theme, pattern, reason, compact, headerTarget) {
    return renderToolOutput(buildGrepBlockedView(theme, pattern, reason, headerTarget), compact);
}
//# sourceMappingURL=restricted_execution.js.map