import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { Box, Text } from "ink";
import { parseActionSummary } from "./ActionSummaryBlock.js";
import { truncateCells } from "./design/textLayout.js";
export function ArtifactApprovalPreviewBlock(props) {
    const model = artifactApprovalPreviewModel(props.summary);
    if (!model)
        return null;
    const width = props.width ?? 96;
    return (_jsxs(Box, { flexDirection: "column", marginTop: 1, children: [_jsxs(Text, { children: [_jsx(Text, { color: riskColor(model.risk), children: model.title }), " ", _jsx(Text, { color: "gray", children: model.risk })] }), _jsx(PreviewRow, { label: model.targetLabel, value: model.target, width: width }), _jsx(PreviewRow, { label: model.sizeLabel, value: model.size, width: width }), _jsx(PreviewRow, { label: "note", value: model.note, width: width, color: "gray" })] }));
}
export function artifactApprovalPreviewModel(summary) {
    const parsed = parseActionSummary(summary);
    if (!parsed)
        return null;
    const fields = Object.fromEntries(parsed.fields.map((field) => [field.key, field.value]));
    if (parsed.action === "create_docx" || parsed.action === "create_pdf") {
        const kind = parsed.action === "create_docx" ? "DOCX" : "PDF";
        return {
            action: parsed.action,
            title: `Create ${kind}`,
            targetLabel: "path",
            target: fields.path || "(unknown path)",
            sizeLabel: "input",
            size: `${fields.markdownChars || "0"} markdown chars`,
            risk: "medium",
            note: "writes a generated document artifact after approval",
        };
    }
    if (parsed.action === "computer_use") {
        return {
            action: "computer_use",
            title: "Computer use",
            targetLabel: "target",
            target: "local desktop automation",
            sizeLabel: "request",
            size: `${fields.instructionChars || "0"} instruction chars`,
            risk: "high",
            note: "may control visible desktop state; keep disabled unless explicitly needed",
        };
    }
    return null;
}
function PreviewRow(props) {
    return (_jsxs(Box, { flexDirection: "row", children: [_jsxs(Text, { color: "gray", children: [props.label.padEnd(9), " "] }), _jsx(Text, { color: props.color ?? "gray", children: truncateCells(props.value, Math.max(16, props.width - 12)) })] }));
}
function riskColor(risk) {
    return risk === "high" ? "yellow" : "cyan";
}
