import React, { useState, useMemo } from 'react'; import { Code, Eye, Copy, Check, ShieldCheck, ExternalLink, } from 'lucide-react'; import { BrandLogo } from '../ui/BrandLogo'; import { parseMarkdownToHtml, isHtmlContent } from '../../lib/markdownUtils'; interface MarkdownViewerProps { content: string; subject?: string; showBrandingHeader?: boolean; className?: string; } export const MarkdownViewer: React.FC = ({ content, subject, showBrandingHeader = true, className = '', }) => { const [viewMode, setViewMode] = useState<'rendered' | 'raw'>('rendered'); const [copied, setCopied] = useState(false); const isHtml = useMemo(() => isHtmlContent(content), [content]); const renderedHtml = useMemo(() => { if (!content) return '

No content

'; if (isHtml) return content; return parseMarkdownToHtml(content); }, [content, isHtml]); const handleCopy = () => { navigator.clipboard.writeText(content); setCopied(true); setTimeout(() => setCopied(false), 2000); }; return (
{/* Top Controls Bar */}
{showBrandingHeader && (
PFM Markdown Engine
)} {isHtml ? 'Format: HTML Email' : 'Format: GitHub Flavored Markdown'}
{/* Toggle View Mode */}
{/* Copy Button */}
{/* Content Rendering */} {viewMode === 'rendered' ? (
{isHtml ? (
) : (
)}
) : (
          {content}
        
)} {/* Branded Footer Stamp */} {showBrandingHeader && (
Verified PFM Secure Platform Formatting
{content.length} characters
)}
); };