'use client'; import React, { useState, useRef } from 'react'; import Link from 'next/link'; import { QRCodeSVG } from 'qrcode.react'; import { Calendar, Download, Check, Sparkles, Clock, MapPin, AlignLeft } 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: '#F5F3FF', // Violet-50 primary: '#7C3AED', // Violet-600 primaryDark: '#6D28D9', // Violet-700 }; // QR Color Options const QR_COLORS = [ { name: 'Violet', value: '#7C3AED' }, { name: 'Purple', value: '#9333EA' }, { name: 'Classic Black', value: '#000000' }, { name: 'Deep Blue', value: '#1E40AF' }, { name: 'Pink', value: '#DB2777' }, { name: 'Emerald', value: '#10B981' }, { name: 'Rose', value: '#F43F5E' }, ]; // Frame Options const FRAME_OPTIONS = [ { id: 'none', label: 'No Frame' }, { id: 'scanme', label: 'Scan Me' }, { id: 'event', label: 'Event' }, { id: 'save', label: 'Save Date' }, ]; export default function EventGenerator() { const [title, setTitle] = useState(''); const [location, setLocation] = useState(''); const [description, setDescription] = useState(''); const [startDate, setStartDate] = useState(''); const [endDate, setEndDate] = useState(''); const [qrColor, setQrColor] = useState(BRAND.primary); const [frameType, setFrameType] = useState('none'); const qrRef = useRef(null); // Format Date for iCal: YYYYMMDDTHHMMSS const formatDate = (dateString: string) => { if (!dateString) return ''; const d = new Date(dateString); // Basic formatting, assumes local time for simplicity in this static tool const year = d.getFullYear(); const month = ('0' + (d.getMonth() + 1)).slice(-2); const day = ('0' + d.getDate()).slice(-2); const hours = ('0' + d.getHours()).slice(-2); const minutes = ('0' + d.getMinutes()).slice(-2); const seconds = ('0' + d.getSeconds()).slice(-2); return `${year}${month}${day}T${hours}${minutes}${seconds}`; }; const qrValue = [ 'BEGIN:VEVENT', `SUMMARY:${title}`, `LOCATION:${location}`, `DESCRIPTION:${description}`, `DTSTART:${formatDate(startDate)}`, `DTEND:${formatDate(endDate)}`, 'END:VEVENT' ].join('\n'); 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 = `event-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 = `event-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 */}
{/* Event Details */}

Event Details

setTitle(e.target.value)} className="h-12 text-base rounded-xl border-slate-200 focus:border-[#7C3AED] focus:ring-[#7C3AED]" />
setStartDate(e.target.value)} className="h-12 text-sm rounded-xl border-slate-200 focus:border-[#1A1265] focus:ring-[#1A1265]" />
setEndDate(e.target.value)} className="h-12 text-sm rounded-xl border-slate-200 focus:border-[#7C3AED] focus:ring-[#7C3AED]" />
setLocation(e.target.value)} className="pl-10 h-12 text-base rounded-xl border-slate-200 focus:border-[#1A1265] focus:ring-[#1A1265]" />