'use client'; import React, { useMemo } from 'react'; import { EmailContent } from '@/types/email'; import { formatEmailContent } from '@/lib/utils/email-content'; interface EmailContentDisplayProps { content: EmailContent | string | null; 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 if provided const processedContent = useMemo(() => { if (!content) { console.log('EmailContentDisplay: No content provided'); return { __html: '
No content available
' }; } try { console.log('EmailContentDisplay processing:', { contentType: typeof content, isNull: content === null, isString: typeof content === 'string', isObject: typeof content === 'object', length: typeof content === 'string' ? content.length : null }); let formattedContent: string; // If it's a string, we need to determine if it's HTML or plain text if (typeof content === 'string') { formattedContent = formatEmailContent({ content }); } // If it's an EmailContent object else { formattedContent = formatEmailContent({ content }); } console.log('EmailContentDisplay processed result length:', formattedContent.length); return { __html: formattedContent }; } catch (error) { console.error('Error processing email content:', error); return { __html: '
Error displaying email content
' }; } }, [content]); // Handle quoted text display const displayHTML = useMemo(() => { if (!showQuotedText) { // Hide quoted text (usually in blockquotes) // This is simplified - a more robust approach would parse and handle // quoted sections more intelligently const htmlWithoutQuotes = processedContent.__html.replace(/]*>[\s\S]*?<\/blockquote>/gi, '
[Quoted text hidden]
'); return { __html: htmlWithoutQuotes }; } return processedContent; }, [processedContent, showQuotedText]); return (
{/* Debug output if enabled */} {debug && (

Content Type: {typeof content === 'string' ? 'Text' : 'HTML'}

HTML Length: {typeof content === 'string' ? content.length : content?.html?.length || 0}

Text Length: {typeof content === 'string' ? content.length : content?.text?.length || 0}

)}
); }; export default EmailContentDisplay;