'use client' import { useState, useCallback } from 'react' import { Copy, Check, Eye, Code } from 'lucide-react' import ReactMarkdown from 'react-markdown' import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter' import { oneDark } from 'react-syntax-highlighter/dist/esm/styles/prism' interface PreviewProps { content: string } export default function Preview({ content }: PreviewProps) { const [view, setView] = useState<'preview' | 'source'>('preview') const [copied, setCopied] = useState(false) const handleCopy = useCallback(async () => { try { await navigator.clipboard.writeText(content) setCopied(true) setTimeout(() => setCopied(false), 2000) } catch { // Fallback for older browsers const textarea = document.createElement('textarea') textarea.value = content document.body.appendChild(textarea) textarea.select() document.execCommand('copy') document.body.removeChild(textarea) setCopied(true) setTimeout(() => setCopied(false), 2000) } }, [content]) return (
{/* Header */}
{/* Content */}
{view === 'preview' ? (
{String(children).replace(/\n$/, '')} ) : ( {children} ) }, h1: ({ children }) => (

{children}

), h2: ({ children }) => (

{children}

), p: ({ children }) => (

{children}

), blockquote: ({ children }) => (
{children}
), ul: ({ children }) => (
    {children}
), li: ({ children }) => (
  • {children}
  • ), }} > {content}
    ) : (
                {content}
              
    )}
    {/* Footer */}
    {content.length} characters • {content.split('\n').length} lines
    ) }