"use client"; import { useState } from "react"; import { useUser } from "@/lib/context"; import { Coffee, ShoppingBag, Music, Film, Dumbbell, Ticket, Check, Coins, Copy, ArrowRight, ShieldCheck } from "lucide-react"; interface BrandVoucher { id: string; brand: string; discount: string; cost: number; icon: React.ReactNode; color: string; bgGlow: string; } export default function SpendSection() { const { profile, claimVoucher, vouchers } = useUser(); const [redeemedCode, setRedeemedCode] = useState<{ brand: string; code: string } | null>(null); const [errorMessage, setErrorMessage] = useState(null); const [copiedId, setCopiedId] = useState(null); const availableVouchers: BrandVoucher[] = [ { id: "v-sbux", brand: "Starbucks", discount: "$10 Gift Card", cost: 150, icon: , color: "border-emerald-500/20 text-emerald-400 hover:border-emerald-500/50", bgGlow: "rgba(16, 185, 129, 0.15)", }, { id: "v-nike", brand: "Nike", discount: "20% Discount Code", cost: 300, icon: , color: "border-white/10 text-white hover:border-white/30", bgGlow: "rgba(255, 255, 255, 0.15)", }, { id: "v-spotify", brand: "Spotify", discount: "1 Month Premium", cost: 200, icon: , color: "border-green-500/20 text-green-400 hover:border-green-500/50", bgGlow: "rgba(34, 197, 94, 0.15)", }, { id: "v-netflix", brand: "Netflix", discount: "1 Month Free UltraHD", cost: 450, icon: , color: "border-red-500/20 text-red-500 hover:border-red-500/50", bgGlow: "rgba(239, 68, 68, 0.15)", }, { id: "v-gymshark", brand: "Gymshark", discount: "30% Storewide Voucher", cost: 250, icon: , color: "border-amber-500/20 text-amber-500 hover:border-amber-500/50", bgGlow: "rgba(245, 158, 11, 0.15)", }, { id: "v-tickets", brand: "Ticketmaster", discount: "$25 Concert Coupon", cost: 400, icon: , color: "border-sky-500/20 text-sky-400 hover:border-sky-500/50", bgGlow: "rgba(56, 189, 248, 0.15)", }, ]; const handleRedeem = (voucher: BrandVoucher) => { if (profile.lytBalance < voucher.cost) { setErrorMessage(`Insufficient LYT balance. You need ${voucher.cost - profile.lytBalance} more LYTs for this voucher.`); setTimeout(() => setErrorMessage(null), 5000); return; } const res = claimVoucher(voucher.brand, voucher.discount, voucher.cost); if (res.success && res.code) { setRedeemedCode({ brand: voucher.brand, code: res.code }); // Clear popup after a while setTimeout(() => setRedeemedCode(null), 10000); } }; const copyToClipboard = (id: string, text: string) => { navigator.clipboard.writeText(text); setCopiedId(id); setTimeout(() => setCopiedId(null), 3000); }; return (
{/* Visual background glows */}
{/* Section Header */}
Spend Your LYTs

Claim Vouchers at Your Favorite Brands

Redeem your accumulated LYT coins for gift cards, subscriptions, and discounts. Click redeem to generate a checkout code.

{/* Dynamic Warning Alert */} {errorMessage && (
{errorMessage} Earn LYTs fast
)} {/* Success Modal Popup */} {redeemedCode && (

Redemption Successful!

You successfully claimed your {redeemedCode.brand} voucher code.

{/* Code Shelf */}
{redeemedCode.code}
Code is also saved to your Active Vouchers panel below.
)} {/* Voucher Grid */}
{availableVouchers.map((voucher) => { const isAffordable = profile.lytBalance >= voucher.cost; return (
{/* Brand Header */}
{voucher.icon}
{voucher.cost} LYTs
{/* Info */}

{voucher.brand}

{voucher.discount}

{/* Bottom action */}
); })}
{/* Claimed Vouchers Display */} {vouchers.length > 0 && (

Your Claimed Vouchers {vouchers.length} Total

{vouchers.map((v) => (
{v.brand}

{v.discount}

Claimed on {v.claimedAt}
{v.code}
))}
)}
); }