import React from 'react'; import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter'; import { cn } from '@/lib/utils'; import { getLanguageFromExtension } from '@/lib/toolHelpers'; import { parseDiffToUnified } from './message/toolRenderers'; interface DiffPreviewProps { diff: string; syntaxTheme: { [key: string]: React.CSSProperties }; filePath?: string; } export const DiffPreview: React.FC = ({ diff, syntaxTheme, filePath }) => (
{parseDiffToUnified(diff).map((hunk, hunkIdx) => (
{`${hunk.file || filePath?.split('/').pop() || 'file'} (line ${hunk.oldStart})`}
{hunk.lines.map((line, lineIdx) => (
{line.lineNumber || ''}
{line.content}
))}
))}
); interface WritePreviewProps { content: string; syntaxTheme: { [key: string]: React.CSSProperties }; filePath?: string; } export const WritePreview: React.FC = ({ content, syntaxTheme, filePath }) => { const lines = content.split('\n'); const language = getLanguageFromExtension(filePath ?? '') || 'text'; const displayPath = filePath?.split('/').pop() || 'New file'; const lineCount = Math.max(lines.length, 1); const headerLineLabel = lineCount === 1 ? 'line 1' : `lines 1-${lineCount}`; return (
{`${displayPath} (${headerLineLabel})`}
{lines.map((line, lineIdx) => (
{lineIdx + 1}
{line || ' '}
))}
); };