import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { Box, Text } from "ink";
export function FileEditResultBlock(props) {
    const model = fileEditResultModel(props.action, props.message ?? "");
    if (!model)
        return null;
    return (_jsxs(Box, { flexDirection: "column", children: [_jsx(FileEditRow, { label: "change", value: model.change }), model.edits !== undefined ? _jsx(FileEditRow, { label: "edits", value: String(model.edits) }) : null] }));
}
export function fileEditResultModel(action, message = "") {
    const trimmed = message.trim();
    if (action === "write_file") {
        return {
            operation: "write",
            change: trimmed || "file written",
        };
    }
    if (action === "apply_patch") {
        const edits = Number(trimmed.match(/^(\d+)\s+edits?$/i)?.[1] ?? NaN);
        return {
            operation: "patch",
            change: Number.isFinite(edits)
                ? `${edits} edit${edits === 1 ? "" : "s"} applied`
                : trimmed || "patch applied",
            ...(Number.isFinite(edits) ? { edits } : {}),
        };
    }
    return null;
}
function FileEditRow(props) {
    return (_jsxs(Box, { flexDirection: "row", children: [_jsxs(Text, { color: "gray", children: [props.label.padEnd(7), " "] }), _jsx(Text, { color: "gray", children: props.value })] }));
}
