'use client'; import React, { useMemo } from 'react'; import { EmailContent } from '@/types/email'; import { processContentWithDirection } from '@/lib/utils/text-direction'; interface EmailContentDisplayProps { content: EmailContent | null | undefined; className?: string; showQuotedText?: boolean; type?: 'html' | 'text' | 'auto'; debug?: boolean; } /** * Unified component for displaying email content in a consistent way * This handles both HTML and plain text content with proper styling and RTL support */ const EmailContentDisplay: React.FC = ({ content, className = '', showQuotedText = true, type = 'auto', debug = false }) => { // Process content with centralized utility const processedContent = useMemo(() => { // Default empty content if (!content) { return { text: '', html: '
No content available
', direction: 'ltr' as const }; } // For text-only display, convert plain text to HTML first if (type === 'text') { const textContent = content.text || ''; const formattedText = textContent .replace(/&/g, '&') .replace(//g, '>') .replace(/\n/g, '
'); return processContentWithDirection(formattedText); } // For auto mode, let the centralized function handle the content return processContentWithDirection(content); }, [content, type]); // Handle quoted text display const displayHTML = useMemo(() => { if (!showQuotedText) { // This is simplified - a more robust approach would parse and handle // quoted sections more intelligently return processedContent.html.replace(/]*>[\s\S]*?<\/blockquote>/gi, '
[Quoted text hidden]
'); } return processedContent.html; }, [processedContent.html, showQuotedText]); return (
{/* Debug output if enabled */} {debug && (

Content Type: {content?.isHtml ? 'HTML' : 'Text'}

Direction: {processedContent.direction}

HTML Length: {content?.html?.length || 0}

Text Length: {content?.text?.length || 0}

)}
); }; export default EmailContentDisplay;