'use client'; import React, { useState, useRef } from 'react'; import Link from 'next/link'; import { QRCodeSVG } from 'qrcode.react'; import { CreditCard, Download, Check, Sparkles, DollarSign } from 'lucide-react'; import { Button } from '@/components/ui/Button'; import { Input } from '@/components/ui/Input'; import { Select } from '@/components/ui/Select'; import { cn } from '@/lib/utils'; // Brand Colors - PayPal Blue const BRAND = { paleGrey: '#EFF6FF', // Blue-50 primary: '#003087', // PayPal Dark Blue primaryDark: '#001F5C', accent: '#0070BA', // PayPal Light Blue }; // QR Color Options const QR_COLORS = [ { name: 'PayPal Blue', value: '#003087' }, { name: 'PayPal Light', value: '#0070BA' }, { name: 'Classic Black', value: '#000000' }, { name: 'Indigo', value: '#4F46E5' }, { name: 'Violet', 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: 'pay', label: 'Pay Now' }, { id: 'donate', label: 'Donate' }, { id: 'tip', label: 'Tip Me' }, ]; // Currency Options const CURRENCIES = [ { value: 'EUR', label: 'EUR (€)' }, { value: 'USD', label: 'USD ($)' }, { value: 'GBP', label: 'GBP (£)' }, { value: 'CHF', label: 'CHF' }, ]; // Input type options const INPUT_TYPES = [ { id: 'username', label: 'PayPal.me Username' }, { id: 'email', label: 'PayPal Email' }, ]; export default function PayPalGenerator() { const [inputType, setInputType] = useState('email'); const [paypalId, setPaypalId] = useState(''); const [amount, setAmount] = useState(''); const [currency, setCurrency] = useState('EUR'); const [qrColor, setQrColor] = useState(BRAND.primary); const [frameType, setFrameType] = useState('none'); const qrRef = useRef(null); // Generate PayPal payment link const generatePayPalLink = () => { if (!paypalId.trim()) return 'https://paypal.com'; if (inputType === 'username') { // PayPal.me link let link = `https://paypal.me/${paypalId.trim()}`; if (amount && parseFloat(amount) > 0) { link += `/${amount}`; } return link; } else { // PayPal email payment link (donation/payment format) const params = new URLSearchParams({ cmd: '_donations', business: paypalId.trim(), currency_code: currency, ...(amount && parseFloat(amount) > 0 ? { amount } : {}), }); return `https://www.paypal.com/cgi-bin/webscr?${params.toString()}`; } }; 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 = `paypal-qr-${paypalId || '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 = `paypal-qr-${paypalId || '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 */}
{/* PayPal Details */}

PayPal Details

{/* Input Type Toggle */}
{INPUT_TYPES.map((type) => ( ))}
setPaypalId(e.target.value)} className="h-12 text-base rounded-xl border-slate-200 focus:border-[#003087] focus:ring-[#003087]" />

{inputType === 'username' ? <>Find yours at paypal.me : 'The email address linked to your PayPal account' }

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