'use client'; import React, { useState, useMemo } from 'react'; import { Card } from '@/ui/Card'; import { Button } from '@/ui/Button'; import { TransactionRow } from '@/components/leagues/TransactionRow'; import type { LeagueWalletViewData } from '@/lib/view-data/leagues/LeagueWalletViewData'; import { Box } from '@/ui/Box'; import { Stack } from '@/ui/Stack'; import { Text } from '@/ui/Text'; import { Heading } from '@/ui/Heading'; import { Container } from '@/ui/Container'; import { Grid } from '@/ui/Grid'; import { Icon as UIIcon } from '@/ui/Icon'; import { Wallet, DollarSign, ArrowUpRight, Clock, AlertTriangle, Download, TrendingUp } from 'lucide-react'; interface WalletTemplateProps { viewData: LeagueWalletViewData; onWithdraw?: (amount: number) => void; onExport?: () => void; mutationLoading?: boolean; } export function LeagueWalletPageClient({ viewData, onWithdraw, onExport, mutationLoading = false }: WalletTemplateProps) { const [withdrawAmount, setWithdrawAmount] = useState(''); const [showWithdrawModal, setShowWithdrawModal] = useState(false); const [filterType, setFilterType] = useState<'all' | 'sponsorship' | 'membership' | 'withdrawal' | 'prize'>('all'); const filteredTransactions = useMemo(() => { if (filterType === 'all') return viewData.transactions; return viewData.transactions.filter(t => t.type === filterType); }, [viewData.transactions, filterType]); const handleWithdrawClick = () => { const amount = parseFloat(withdrawAmount); if (!amount || amount <= 0) return; if (onWithdraw) { onWithdraw(amount); setShowWithdrawModal(false); setWithdrawAmount(''); } }; const canWithdraw = viewData.balance > 0; const withdrawalBlockReason = !canWithdraw ? 'Balance is zero' : undefined; return ( {/* Header */} League Wallet Manage your league's finances and payouts {/* Withdrawal Warning */} {!canWithdraw && withdrawalBlockReason && ( Withdrawals Temporarily Unavailable {withdrawalBlockReason} )} {/* Stats Grid */} {viewData.formattedBalance} Available Balance {viewData.formattedTotalRevenue} Total Revenue {viewData.formattedTotalFees} Platform Fees (10%) {viewData.formattedPendingPayouts} Pending Payouts {/* Transactions */} Transaction History ) => setFilterType(e.target.value as typeof filterType)} p={1.5} rounded="lg" border borderColor="border-charcoal-outline" bg="bg-iron-gray" color="text-white" fontSize="sm" > All Transactions Sponsorships Memberships Withdrawals Prizes {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 {viewData.formattedBalance} Available after Season 2 ends (estimated: Jan 15, 2026) {/* Withdraw Modal */} {showWithdrawModal && onWithdraw && ( Withdraw Funds {!canWithdraw ? ( {withdrawalBlockReason} ) : ( Amount to Withdraw $ ) => setWithdrawAmount(e.target.value)} max={viewData.balance} w="full" pl={8} pr={4} py={2} rounded="lg" border borderColor="border-charcoal-outline" bg="bg-iron-gray" color="text-white" placeholder="0.00" /> Available: {viewData.formattedBalance} Destination Bank Account ***1234 )} )} {/* 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. ); }