'use client'; import React, { useState, useRef } from 'react'; import Link from 'next/link'; import { QRCodeSVG } from 'qrcode.react'; import { Mail, Download, Check, Sparkles, Type, FileText } from 'lucide-react'; import { Button } from '@/components/ui/Button'; import { Input } from '@/components/ui/Input'; import { cn } from '@/lib/utils'; // Brand Colors const BRAND = { paleGrey: '#EBEBDF', richRed: '#dc2626', }; // QR Color Options const QR_COLORS = [ { name: 'Classic Black', value: '#000000' }, { name: 'Email Red', value: '#dc2626' }, { name: 'Deep Blue', value: '#1E40AF' }, { name: 'Violet', value: '#7C3AED' }, { name: 'Teal', value: '#0D9488' }, { name: 'Coral', value: '#F43F5E' }, { name: 'Emerald', value: '#10B981' }, { name: 'Rose', value: '#F43F5E' }, ]; // Frame Options const FRAME_OPTIONS = [ { id: 'none', label: 'No Frame' }, { id: 'email', label: 'Email Me' }, { id: 'contact', label: 'Contact' }, { id: 'send', label: 'Send Mail' }, ]; export default function EmailGenerator() { const [formData, setFormData] = useState({ email: '', subject: '', body: '' }); const [qrColor, setQrColor] = useState('#dc2626'); const [frameType, setFrameType] = useState('none'); const qrRef = useRef(null); // Generate Mailto Link // Format: mailto:email?subject=...&body=... const getMailtoUrl = () => { const params = new URLSearchParams(); if (formData.subject) params.append('subject', formData.subject); if (formData.body) params.append('body', formData.body); const queryString = params.toString(); return `mailto:${formData.email}${queryString ? `?${queryString}` : ''}`; }; const handleDownload = async (format: 'png' | 'svg') => { if (!qrRef.current) return; try { if (format === 'png') { const { toPng } = await import('html-to-image'); const dataUrl = await toPng(qrRef.current, { cacheBust: true, pixelRatio: 3 }); const link = document.createElement('a'); link.download = `email-qr-code.png`; link.href = dataUrl; link.click(); } else { const svgData = qrRef.current.querySelector('svg')?.outerHTML; if (svgData) { const blob = new Blob([svgData], { type: 'image/svg+xml;charset=utf-8' }); const urlBlob = URL.createObjectURL(blob); const link = document.createElement('a'); link.href = urlBlob; link.download = `email-qr-code.svg`; link.click(); } } } catch (err) { console.error('Download failed', err); } }; const getFrameLabel = () => { const frame = FRAME_OPTIONS.find(f => f.id === frameType); return frame?.id !== 'none' ? frame?.label : null; }; const handleChange = (e: React.ChangeEvent) => { setFormData({ ...formData, [e.target.name]: e.target.value }); }; return (
{/* Main Generator Card */}
{/* LEFT: Input Section */}
{/* Input Fields */}

Email Details