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 RemoteFileApprovalPreviewBlock(props) {
    const model = remoteFileApprovalPreviewModel(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: model.risk === "high" ? "yellow" : "cyan", children: model.title }), " ", _jsx(Text, { color: "gray", children: model.risk })] }), _jsx(PreviewRow, { label: "profile", value: model.profile, width: width }), _jsx(PreviewRow, { label: "path", value: model.path, width: width }), _jsx(PreviewRow, { label: "operation", value: model.operation, width: width }), _jsx(PreviewRow, { label: "impact", value: model.impact, width: width }), model.fingerprint ? _jsx(PreviewRow, { label: "sha", value: model.fingerprint, width: width }) : null, _jsx(PreviewRow, { label: "note", value: model.note, width: width, color: "gray" })] }));
}
export function remoteFileApprovalPreviewModel(summary) {
    const parsed = parseActionSummary(summary);
    if (!parsed || parsed.action !== "ssh_write_file")
        return null;
    const fields = Object.fromEntries(parsed.fields.map((field) => [field.key, field.value]));
    const overwrite = fields.overwrite === "true";
    const lines = fields.lines ? ` / ${fields.lines} lines` : "";
    return {
        action: "ssh_write_file",
        title: overwrite ? "Overwrite remote file" : "Create remote file",
        profile: fields.profile || "(unknown)",
        path: fields.path || "(unknown path)",
        operation: overwrite ? "replace remote file content" : "write new remote file",
        impact: `${fields.chars || "0"} chars${lines}`,
        fingerprint: fields.sha || "",
        risk: overwrite ? "high" : "medium",
        note: "remote file writes cannot be locally diff-previewed; inspect the target profile carefully",
    };
}
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)) })] }));
}
