"use client" import { useState, useEffect, useRef } from "react" import { Button } from "@/components/ui/button" import { Heart, Sparkles, TrendingUp } from "lucide-react" interface Props { onSelect: (amountPence: number) => void eventName: string eventId?: string } interface AiSuggestion { amounts: number[] nudge: string socialProof: string } const FALLBACK_AMOUNTS = [2000, 5000, 10000, 25000, 50000, 100000] export function AmountStep({ onSelect, eventName, eventId }: Props) { const [custom, setCustom] = useState("") const [selected, setSelected] = useState(null) const [suggestions, setSuggestions] = useState(null) const [hovering, setHovering] = useState(null) const inputRef = useRef(null) // Fetch AI-powered suggestions useEffect(() => { const url = eventId ? `/api/ai/suggest?eventId=${eventId}` : "/api/ai/suggest" fetch(url) .then(r => r.json()) .then(data => { if (data.amounts?.length) setSuggestions(data) }) .catch(() => {}) }, [eventId]) const amounts = suggestions?.amounts || FALLBACK_AMOUNTS const handlePreset = (amount: number) => { setSelected(amount) setCustom("") // Haptic feedback on mobile if (navigator.vibrate) navigator.vibrate(10) } const handleCustomChange = (value: string) => { const clean = value.replace(/[^0-9.]/g, "") setCustom(clean) setSelected(null) } const handleContinue = () => { const amount = selected || Math.round(parseFloat(custom) * 100) if (amount >= 100) onSelect(amount) } const activeAmount = selected || (custom ? Math.round(parseFloat(custom) * 100) : 0) const isValid = activeAmount >= 100 const giftAidBonus = Math.round(activeAmount * 0.25) return (
{/* Hero */}

Make a Pledge

for {eventName}

{/* Social proof */} {suggestions?.socialProof && (
{[...Array(3)].map((_, i) => (
{["A", "S", "M"][i]}
))}

{suggestions.socialProof}

)} {/* Amount grid */}
{amounts.map((amount) => { const isSelected = selected === amount const isHovering = hovering === amount const pounds = amount / 100 return ( ) })}
{/* AI nudge */} {suggestions?.nudge && (

{suggestions.nudge}

)} {/* Custom amount — premium input */}
£ handleCustomChange(e.target.value)} className="w-full pl-10 pr-4 h-16 text-2xl font-black text-center rounded-2xl border-2 border-gray-200 bg-white focus:border-trust-blue focus:ring-4 focus:ring-trust-blue/10 outline-none transition-all" />
{/* Live Gift Aid preview */} {isValid && (

With Gift Aid:{" "} your £{(activeAmount / 100).toFixed(0)} becomes{" "} £{((activeAmount + giftAidBonus) / 100).toFixed(0)}

HMRC adds 25% — at zero cost to you

)} {/* Continue */}

No payment now — choose how to pay on the next step

) }