import { useMemo, useState } from 'react'; import { ChevronDown, ChevronRight, FileCode } from 'lucide-react'; interface Props { diff: string; } const INITIAL_LINES = 10; export function DiffSnippet({ diff }: Props) { const [expanded, setExpanded] = useState(false); const lines = useMemo(() => diff.split('\n'), [diff]); const totalLines = lines.length; // Find the first and last content lines (skip leading ---/+++ headers) const firstContentIdx = lines.findIndex( (l) => l.startsWith('+') || l.startsWith('-') || l.startsWith(' '), ); // Count content lines that are either +, -, or context lines const contentLineCount = lines.filter( (l) => l.startsWith('+') || l.startsWith('-') || l.startsWith(' '), ).length; // Show first N content lines, plus header lines const displayLines = useMemo(() => { const sliceEnd = expanded ? lines.length : Math.min(firstContentIdx + INITIAL_LINES + contentLineCount, lines.length); return lines.slice(0, sliceEnd); }, [lines, expanded, firstContentIdx, contentLineCount]); const hasMore = totalLines > displayLines.length; if (totalLines === 0) return null; return (