import { useState } from "react"; import type { Change } from "../api/types"; import { WrapIcon } from "./icons"; function DiffView({ content, wrap }: { content: string; wrap: boolean }) { const lines = content.split("\n"); return (
			
				{lines.map((line, i) => {
					let cls = "";
					if (line.startsWith("+++") || line.startsWith("---")) cls = "diff-meta";
					else if (line.startsWith("@@")) cls = "diff-hunk";
					else if (line.startsWith("+")) cls = "diff-add";
					else if (line.startsWith("-")) cls = "diff-del";
					else if (line.startsWith("diff ") || line.startsWith("index ")) cls = "diff-meta";
					return (
						
{line || " "}
); })}
); } function fmtValue(v: unknown): string { if (v === null || v === undefined) return "∅"; if (typeof v === "object") return JSON.stringify(v); return String(v); } function percentDelta(before: unknown, after: unknown): string | null { const b = Number(before); const a = Number(after); if (!Number.isFinite(b) || !Number.isFinite(a) || b === 0) return null; const pct = Math.round(((a - b) / Math.abs(b)) * 100); if (pct === 0) return null; return `${pct > 0 ? "+" : ""}${pct}%`; } function BeforeAfter({ before, after, contentType, }: { before: unknown; after: unknown; contentType?: string | null; }) { const delta = contentType === "integer" || contentType === "number" ? percentDelta(before, after) : null; return (
{fmtValue(before)} {fmtValue(after)} {delta && {delta}} {contentType && ({contentType})}
); } function typeChip(label: string, color: string) { return {label}; } export function ChangeCard({ change, index }: { change: Change; index: number }) { const [wrap, setWrap] = useState(false); return (
#{index + 1}
{change.type === "unified_diff" && ( <> {typeChip("diff", "bg-primary-dim/40 text-primary")} {change.path} )} {change.type === "config" && ( <> {typeChip("config", "bg-accent/15 text-accent")} {change.path} )} {change.type === "custom" && ( <> {typeChip("custom", "bg-changes/15 text-changes")} {change.label} )}
{/* Wrapping beats horizontal scrolling for long lines on a phone. */} {change.type === "unified_diff" && ( )}
{change.type === "unified_diff" && } {change.type === "config" && ( )} {change.type === "custom" && }
); } export function ChangeList({ changes }: { changes: Change[] }) { return (
{changes.map((c, i) => ( ))}
); }