import { useMemo, type ReactNode } from 'react' import { detectFileReferences } from '@/lib/fileReferences' interface FileReferenceTextProps { text: string onFileClick?: (filePath: string) => void } export function FileReferenceText({ text, onFileClick }: FileReferenceTextProps) { const parts = useMemo(() => { if (!onFileClick) return text const references = detectFileReferences(text) if (references.length === 0) return text const segments: ReactNode[] = [] let lastIndex = 0 references.forEach((ref, index) => { if (ref.startIndex > lastIndex) { segments.push(text.slice(lastIndex, ref.startIndex)) } segments.push( , ) lastIndex = ref.endIndex }) if (lastIndex < text.length) { segments.push(text.slice(lastIndex)) } return segments }, [text, onFileClick]) return <>{parts} }