'use client'; import React, { useState, useMemo } from 'react'; import { Paper, Stack, Title, Text, SegmentedControl, Box, Group, Badge, ScrollArea, ActionIcon, Tooltip, } from '@mantine/core'; import { IconDeviceMobile, IconDeviceDesktop, IconCode } from '@tabler/icons-react'; import { EmailTemplate } from '../../types'; interface EmailPreviewProps { template: EmailTemplate | string; data?: any; showDeviceFrames?: boolean; className?: string; } export function EmailPreview({ template, data = {}, showDeviceFrames = true, className, }: EmailPreviewProps) { const [viewMode, setViewMode] = useState<'desktop' | 'mobile' | 'html'>('desktop'); const [format, setFormat] = useState<'html' | 'text'>('html'); // Compile template const compiled = useMemo(() => { if (typeof template === 'string') { return { subject: 'No subject', html: '
Template not found
', text: 'Template not found', }; } const subject = typeof template.subject === 'function' ? template.subject(data) : template.subject; const html = typeof template.body.html === 'function' ? template.body.html(data) : template.body.html; const text = template.body.text ? typeof template.body.text === 'function' ? template.body.text(data) : template.body.text : 'Text version not available'; return { subject, html, text }; }, [template, data]); const renderContent = () => { if (format === 'text') { return ({compiled.html}