'use client'; import { useState } from 'react'; import { Loader2, Paperclip, User } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { Badge } from '@/components/ui/badge'; import { ScrollArea } from '@/components/ui/scroll-area'; import { sanitizeHtml } from '@/lib/utils/email-formatter'; import { Avatar } from '@/components/ui/avatar'; import { AvatarFallback, AvatarImage } from '@/components/ui/avatar'; import { Card } from '@/components/ui/card'; interface EmailAddress { name: string; address: string; } interface EmailMessage { id: string; messageId?: string; subject: string; from: EmailAddress[]; to: EmailAddress[]; cc?: EmailAddress[]; bcc?: EmailAddress[]; date: Date | string; flags?: { seen: boolean; flagged: boolean; answered: boolean; deleted: boolean; draft: boolean; }; preview?: string; content?: string; html?: string; text?: string; hasAttachments?: boolean; attachments?: Array<{ filename: string; contentType: string; size: number; path?: string; content?: string; }>; folder?: string; size?: number; contentFetched?: boolean; } interface EmailPreviewProps { email: EmailMessage | null; loading?: boolean; onReply?: (type: 'reply' | 'reply-all' | 'forward') => void; } export default function EmailPreview({ email, loading = false, onReply }: EmailPreviewProps) { // Format the date const formatDate = (date: Date | string) => { if (!date) return ''; const dateObj = date instanceof Date ? date : new Date(date); return dateObj.toLocaleString('en-US', { weekday: 'short', year: 'numeric', month: 'short', day: 'numeric', hour: '2-digit', minute: '2-digit' }); }; // Format email addresses const formatEmailAddresses = (addresses: Array<{name: string, address: string}> | undefined) => { if (!addresses || addresses.length === 0) return ''; return addresses.map(addr => addr.name && addr.name !== addr.address ? `${addr.name} <${addr.address}>` : addr.address ).join(', '); }; // Get sender initials for avatar const getSenderInitials = (sender: EmailAddress | undefined) => { if (!sender) return 'U'; if (sender.name) { const parts = sender.name.split(' '); if (parts.length > 1) { return `${parts[0][0]}${parts[parts.length - 1][0]}`.toUpperCase(); } return sender.name[0].toUpperCase(); } return sender.address[0].toUpperCase(); }; // Display loading state if (loading) { return (
Loading email...
Select an email to view
No content available
)}