'use client'; import React, { useMemo, CSSProperties } from 'react'; import { renderEmailContent } from '@/lib/utils/email-utils'; import { EmailContent } from '@/types/email'; 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 */ const EmailContentDisplay: React.FC = ({ content, className = '', showQuotedText = true, type = 'auto', debug = false }) => { // Basic fallback for missing content const safeContent = content || { text: 'No content available', html: '', isHtml: false, direction: 'ltr' }; // Render the content with basic error handling const htmlContent = useMemo(() => { try { return renderEmailContent(safeContent); } catch (error) { console.error('Error rendering content:', error); return `
Error rendering email content
`; } }, [safeContent, type]); // Apply quoted text styling if needed const containerStyle: CSSProperties = showQuotedText ? {} : { maxHeight: '400px', overflowY: 'auto' }; return (
{/* Debug output if enabled */} {debug && (

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

Direction: {safeContent.direction}

Has HTML: {!!safeContent.html}

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

)}
); }; export default EmailContentDisplay;