'use client'; import React, { useState, useRef } from 'react'; import Link from 'next/link'; import { QRCodeSVG } from 'qrcode.react'; import { Phone, Download, Check, Sparkles, MessageCircle, Send } from 'lucide-react'; import { Button } from '@/components/ui/Button'; import { Input } from '@/components/ui/Input'; import { cn } from '@/lib/utils'; import { Textarea } from '@/components/ui/Textarea'; // Brand Colors const BRAND = { paleGrey: '#EBEBDF', richBlue: '#1A1265', richBlueLight: '#2A2275', }; // QR Color Options - WhatsApp Theme const QR_COLORS = [ { name: 'WhatsApp Green', value: '#25D366' }, { name: 'Teal', value: '#128C7E' }, { name: 'Classic Black', value: '#000000' }, { name: 'Rich Blue', value: '#1A1265' }, { name: 'Purple', value: '#7C3AED' }, { name: 'Emerald', value: '#10B981' }, { name: 'Rose', value: '#F43F5E' }, ]; // Frame Options const FRAME_OPTIONS = [ { id: 'none', label: 'No Frame' }, { id: 'scanme', label: 'Scan Me' }, { id: 'chat', label: 'Chat With Us' }, { id: 'support', label: 'Support' }, ]; export default function WhatsappGenerator() { const [phone, setPhone] = useState(''); const [message, setMessage] = useState(''); const [qrColor, setQrColor] = useState('#25D366'); const [frameType, setFrameType] = useState('none'); const qrRef = useRef(null); // WhatsApp URL: https://wa.me/number?text=message const getUrl = () => { const cleanPhone = phone.replace(/\D/g, ''); // Remove non-digits const encodedMessage = encodeURIComponent(message); return `https://wa.me/${cleanPhone}?text=${encodedMessage}`; }; 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 = `whatsapp-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 url = URL.createObjectURL(blob); const link = document.createElement('a'); link.href = url; link.download = `whatsapp-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; }; return (
{/* Main Generator Card */}
{/* LEFT: Input Section */}
{/* WhatsApp Details */}

WhatsApp Details

setPhone(e.target.value)} className="h-12 text-base rounded-xl border-slate-200 focus:border-[#25D366] focus:ring-[#25D366]" />

Include country code (e.g. 1 for US, 44 for UK). No '+' symbol.