import React from 'react'; import { ChevronLeft, Reply, ReplyAll, Forward, Star, MoreHorizontal } from 'lucide-react'; import { ScrollArea } from '@/components/ui/scroll-area'; import { Avatar, AvatarFallback } from '@/components/ui/avatar'; import { Button } from '@/components/ui/button'; import { Email } from '@/hooks/use-courrier'; interface EmailDetailViewProps { email: Email & { html?: string; text?: string }; onBack: () => void; onReply: () => void; onReplyAll: () => void; onForward: () => void; onToggleStar: () => void; } export default function EmailDetailView({ email, onBack, onReply, onReplyAll, onForward, onToggleStar }: EmailDetailViewProps) { // Format date for display const formatDate = (dateString: string) => { const date = new Date(dateString); const now = new Date(); if (date.toDateString() === now.toDateString()) { return date.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' }); } else { return date.toLocaleDateString([], { month: 'short', day: 'numeric' }); } }; // Render email content based on the email body const renderEmailContent = () => { try { // Use fallback for content, html, or text return
; } catch (e) { console.error('Error rendering email:', e); return
Failed to render email content
; } }; return ( <> {/* Email actions header */}

{email.subject}

{/* Scrollable content area */}
{(email.from?.[0]?.name || '').charAt(0) || (email.from?.[0]?.address || '').charAt(0) || '?'}

{email.from?.[0]?.name || ''} <{email.from?.[0]?.address || ''}>

to {email.to?.[0]?.address || ''}

{email.cc && email.cc.length > 0 && (

cc {email.cc.map(c => c.address).join(', ')}

)}
{formatDate(email.date)}
{/* Email content */}
{renderEmailContent()}
{/* Attachments (if any) */} {email.hasAttachments && email.attachments && email.attachments.length > 0 && (

Attachments

{email.attachments.map((attachment, idx) => (

{attachment.filename}

{(attachment.size / 1024).toFixed(1)} KB

))}
)}
); }