"use client";
import { jsx as _jsx } from "react/jsx-runtime";
import { useMemo } from "react";
import { cn } from "@stigmer/theme";
import { DiffViewer } from "./DiffViewer.js";
import { parseUnifiedDiff } from "./parseUnifiedDiff.js";
/**
 * The single canonical renderer for a unified-diff patch *string*.
 *
 * It parses the patch into hunks and renders them through {@link DiffViewer} —
 * the same accessible table (line numbers, colored row backgrounds, a narrow
 * `+`/`-` gutter column, `--stgm-diff-*` tokens) that a computed before/after
 * diff uses — so a harness that only emits a ready unified diff (the Cursor
 * harness's `diffString`) looks line-for-line identical to a native whole-file
 * diff. The `---`/`+++`/`@@` preamble parses into metadata and never reaches the
 * screen; a single-hunk diff shows no `@@` separator at all.
 *
 * Fallback: if the patch cannot be parsed into any hunk (a malformed or
 * non-standard payload) it renders verbatim in a `<pre>` so we show something
 * truthful rather than a misleading "No changes". Color is never the sole
 * channel in either path — the gutter marker / literal prefix carries the change
 * type for non-color readers.
 *
 * Internal to the SDK (not barrel-exported); consumed by {@link ResultView} and
 * {@link FileChangeDiff}.
 */
export function UnifiedDiffView({ patch, className }) {
    const hunks = useMemo(() => parseUnifiedDiff(patch), [patch]);
    if (hunks.length > 0) {
        return _jsx(DiffViewer, { hunks: hunks, className: className });
    }
    // Unparseable but non-empty: show the raw patch rather than nothing.
    const lines = patch.split("\n");
    return (_jsx("pre", { className: cn("max-h-96 overflow-auto whitespace-pre-wrap break-words rounded-md border border-border bg-muted-subtle p-2 font-mono text-xs", className), children: lines.map((line, i) => (_jsx("div", { className: cn(line.startsWith("+") && !line.startsWith("+++") && "text-diff-added-fg", line.startsWith("-") && !line.startsWith("---") && "text-diff-removed-fg", line.startsWith("@@") && "text-diff-hunk-header-fg"), children: line || " " }, i))) }));
}
//# sourceMappingURL=UnifiedDiffView.js.map