'use client'; import { useState, useRef, useEffect } from 'react'; // Remove direct import of server components import { X, Paperclip, ChevronDown, ChevronUp, SendHorizontal, Loader2, AlignLeft, AlignRight } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { Card, CardContent, CardHeader, CardTitle, CardFooter } from '@/components/ui/card'; import DOMPurify from 'isomorphic-dompurify'; // Define EmailMessage interface locally instead of importing from server-only file 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?: any[]; folder?: string; size?: number; contentFetched?: boolean; } // Simplified formatEmailForReplyOrForward that doesn't rely on server code function formatEmailForReplyOrForward( email: EmailMessage, type: 'reply' | 'reply-all' | 'forward' ): { to: string; cc?: string; subject: string; body: string; } { // Format subject let subject = email.subject || ''; if (type === 'reply' || type === 'reply-all') { if (!subject.startsWith('Re:')) { subject = `Re: ${subject}`; } } else if (type === 'forward') { if (!subject.startsWith('Fwd:')) { subject = `Fwd: ${subject}`; } } // Create quote header const date = typeof email.date === 'string' ? new Date(email.date) : email.date; const formattedDate = date.toLocaleString('en-US', { weekday: 'short', year: 'numeric', month: 'short', day: 'numeric', hour: '2-digit', minute: '2-digit' }); const sender = email.from[0]; const fromText = sender?.name ? `${sender.name} <${sender.address}>` : sender?.address || 'Unknown sender'; const quoteHeader = `
${initialEmail.text || ''}`,
{
ADD_ATTR: ['style', 'class'],
ALLOW_DATA_ATTR: true,
USE_PROFILES: { html: true }
}
);
}
// Set the original content for display
setOriginalContent(`${headerHtml}