'use client'; import { useState, useEffect } from 'react'; import { useParams } from 'next/navigation'; import Card from '@/components/ui/Card'; import Button from '@/components/ui/Button'; import { Wallet, DollarSign, ArrowUpRight, ArrowDownLeft, Clock, AlertTriangle, CheckCircle, XCircle, Download, CreditCard, TrendingUp, Calendar } from 'lucide-react'; interface Transaction { id: string; type: 'sponsorship' | 'membership' | 'withdrawal' | 'prize'; description: string; amount: number; fee: number; netAmount: number; date: Date; status: 'completed' | 'pending' | 'failed'; reference?: string; } interface WalletData { balance: number; currency: string; totalRevenue: number; totalFees: number; totalWithdrawals: number; pendingPayouts: number; transactions: Transaction[]; canWithdraw: boolean; withdrawalBlockReason?: string; } // Mock data for demonstration const MOCK_WALLET: WalletData = { balance: 2450.00, currency: 'USD', totalRevenue: 3200.00, totalFees: 320.00, totalWithdrawals: 430.00, pendingPayouts: 150.00, canWithdraw: false, withdrawalBlockReason: 'Season 2 is still active. Withdrawals are available after season completion.', transactions: [ { id: 'txn-1', type: 'sponsorship', description: 'Main Sponsor - TechCorp', amount: 1200.00, fee: 120.00, netAmount: 1080.00, date: new Date('2025-12-01'), status: 'completed', reference: 'SP-2025-001', }, { id: 'txn-2', type: 'sponsorship', description: 'Secondary Sponsor - RaceFuel', amount: 400.00, fee: 40.00, netAmount: 360.00, date: new Date('2025-12-01'), status: 'completed', reference: 'SP-2025-002', }, { id: 'txn-3', type: 'membership', description: 'Season Fee - 32 drivers', amount: 1600.00, fee: 160.00, netAmount: 1440.00, date: new Date('2025-11-15'), status: 'completed', reference: 'MF-2025-032', }, { id: 'txn-4', type: 'withdrawal', description: 'Bank Transfer - Season 1 Payout', amount: -430.00, fee: 0, netAmount: -430.00, date: new Date('2025-10-30'), status: 'completed', reference: 'WD-2025-001', }, { id: 'txn-5', type: 'prize', description: 'Championship Prize Pool (reserved)', amount: -150.00, fee: 0, netAmount: -150.00, date: new Date('2025-12-05'), status: 'pending', reference: 'PZ-2025-001', }, ], }; function TransactionRow({ transaction }: { transaction: Transaction }) { const isIncoming = transaction.amount > 0; const typeIcons = { sponsorship: DollarSign, membership: CreditCard, withdrawal: ArrowUpRight, prize: TrendingUp, }; const TypeIcon = typeIcons[transaction.type]; const statusConfig = { completed: { color: 'text-performance-green', bg: 'bg-performance-green/10', icon: CheckCircle }, pending: { color: 'text-warning-amber', bg: 'bg-warning-amber/10', icon: Clock }, failed: { color: 'text-racing-red', bg: 'bg-racing-red/10', icon: XCircle }, }; const status = statusConfig[transaction.status]; const StatusIcon = status.icon; return (
{isIncoming ? ( ) : ( )}
{transaction.description} {transaction.status}
{transaction.type} {transaction.reference && ( <> {transaction.reference} )} {transaction.date.toLocaleDateString()}
{isIncoming ? '+' : ''}{transaction.amount < 0 ? '-' : ''}${Math.abs(transaction.amount).toFixed(2)}
{transaction.fee > 0 && (
Fee: ${transaction.fee.toFixed(2)}
)}
); } export default function LeagueWalletPage() { const params = useParams(); const [wallet, setWallet] = useState(MOCK_WALLET); const [withdrawAmount, setWithdrawAmount] = useState(''); const [showWithdrawModal, setShowWithdrawModal] = useState(false); const [processing, setProcessing] = useState(false); const [filterType, setFilterType] = useState<'all' | 'sponsorship' | 'membership' | 'withdrawal' | 'prize'>('all'); const filteredTransactions = wallet.transactions.filter( t => filterType === 'all' || t.type === filterType ); const handleWithdraw = async () => { if (!withdrawAmount || parseFloat(withdrawAmount) <= 0) return; setProcessing(true); try { const response = await fetch(`/api/wallets/${params.id}/withdraw`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ amount: parseFloat(withdrawAmount), currency: wallet.currency, seasonId: 'season-2', // Current active season destinationAccount: 'bank-account-***1234', }), }); const result = await response.json(); if (!response.ok) { alert(result.reason || result.error || 'Withdrawal failed'); return; } alert(`Withdrawal of $${withdrawAmount} processed successfully!`); setShowWithdrawModal(false); setWithdrawAmount(''); // Refresh wallet data } catch (err) { console.error('Withdrawal error:', err); alert('Failed to process withdrawal'); } finally { setProcessing(false); } }; return (
{/* Header */}

League Wallet

Manage your league's finances and payouts

{/* Withdrawal Warning */} {!wallet.canWithdraw && wallet.withdrawalBlockReason && (

Withdrawals Temporarily Unavailable

{wallet.withdrawalBlockReason}

)} {/* Stats Grid */}
${wallet.balance.toFixed(2)}
Available Balance
${wallet.totalRevenue.toFixed(2)}
Total Revenue
${wallet.totalFees.toFixed(2)}
Platform Fees (10%)
${wallet.pendingPayouts.toFixed(2)}
Pending Payouts
{/* Transactions */}

Transaction History

{filteredTransactions.length === 0 ? (

No Transactions

{filterType === 'all' ? 'Revenue from sponsorships and fees will appear here.' : `No ${filterType} transactions found.`}

) : (
{filteredTransactions.map((transaction) => ( ))}
)}
{/* Revenue Breakdown */}

Revenue Breakdown

Sponsorships
$1,600.00
Membership Fees
$1,600.00
Total Gross Revenue $3,200.00
Platform Fee (10%) -$320.00
Net Revenue $2,880.00

Payout Schedule

Season 2 Prize Pool Pending

Distributed after season completion to top 3 drivers

Available for Withdrawal ${wallet.balance.toFixed(2)}

Available after Season 2 ends (estimated: Jan 15, 2026)

{/* Withdraw Modal */} {showWithdrawModal && (

Withdraw Funds

{!wallet.canWithdraw ? (

{wallet.withdrawalBlockReason}

) : ( <>
$ setWithdrawAmount(e.target.value)} max={wallet.balance} className="w-full pl-8 pr-4 py-2 rounded-lg border border-charcoal-outline bg-iron-gray text-white focus:border-primary-blue focus:outline-none" placeholder="0.00" />

Available: ${wallet.balance.toFixed(2)}

)}
)} {/* Alpha Notice */}

Alpha Note: Wallet management is demonstration-only. Real payment processing and bank integrations will be available when the payment system is fully implemented. The 10% platform fee and season-based withdrawal restrictions are enforced in the actual implementation.

); }