/** * Email Customizer Preview Panel * Contains the preview frame with device switching and test email functionality */ import { useState } from 'react'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { Switch } from '@/components/ui/switch'; import { Label } from '@/components/ui/label'; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from '@/components/ui/dialog'; import { Send, Loader2, Moon } from 'lucide-react'; import { DeviceSwitcher, EmailPreviewFrame } from './preview'; import type { EmailCustomizerSettings, DevicePreview } from './types'; import type { ProductCardConfig, CouponDisplayConfig } from './sections'; interface CustomizerPreviewProps { settings: EmailCustomizerSettings; devicePreview: DevicePreview; onDeviceChange: (device: DevicePreview) => void; darkModePreview: boolean; onDarkModeChange: (enabled: boolean) => void; onSendTestEmail: (email: string, emailType: string) => Promise; isSendingTest: boolean; selectedEmailType?: string; emailHeading?: string; emailBody?: string; emailAdditionalContent?: string; emailPreheaderText?: string; productCard?: ProductCardConfig; couponDisplay?: CouponDisplayConfig; } export function CustomizerPreview({ settings, devicePreview, onDeviceChange, darkModePreview, onDarkModeChange, onSendTestEmail, isSendingTest, selectedEmailType = 'subscription_new', emailHeading = 'Your Subscription is Active', emailBody, emailAdditionalContent = '', emailPreheaderText = '', productCard, couponDisplay, }: CustomizerPreviewProps) { const [showTestDialog, setShowTestDialog] = useState(false); const [testEmail, setTestEmail] = useState(''); const [testEmailError, setTestEmailError] = useState(''); const handleSendTestEmail = async () => { if (!testEmail) { setTestEmailError('Please enter an email address'); return; } if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(testEmail)) { setTestEmailError('Please enter a valid email address'); return; } setTestEmailError(''); try { await onSendTestEmail(testEmail, selectedEmailType); setShowTestDialog(false); setTestEmail(''); } catch { setTestEmailError('Failed to send test email. Please try again.'); } }; return (
{/* Preview Toolbar */}
{/* Dark Mode Toggle */}
{/* Preview Area */}
{/* Test Email Dialog */} Send Test Email Send a test email with the current customization settings to preview how it will look in an email client.
{ setTestEmail(e.target.value); setTestEmailError(''); }} className={testEmailError ? 'border-destructive' : ''} /> {testEmailError && (

{testEmailError}

)}

The test email will be sent with sample data and your current customization settings.

); } export default CustomizerPreview;