'use client'; import { Button } from '@/ui/Button'; import { Heading } from '@/ui/Heading'; import { Icon } from '@/ui/Icon'; import { Input } from '@/ui/Input'; import { Stack } from '@/ui/Stack'; import { Text } from '@/ui/Text'; import { Calendar, DollarSign, TrendingUp, User } from 'lucide-react'; import { useState } from 'react'; type FeeType = 'season' | 'monthly' | 'per_race'; interface MembershipFeeConfig { type: FeeType; amount: number; enabled: boolean; } interface LeagueMembershipFeesSectionProps { leagueId: string; seasonId?: string; readOnly?: boolean; } export function LeagueMembershipFeesSection({ readOnly = false }: LeagueMembershipFeesSectionProps) { const [feeConfig, setFeeConfig] = useState({ type: 'season', amount: 0, enabled: false, }); const [tempAmount, setTempAmount] = useState('0'); const [editing, setEditing] = useState(false); const handleEnableFees = () => { setFeeConfig({ ...feeConfig, enabled: true }); setEditing(true); setTempAmount(feeConfig.amount.toString()); }; const handleSave = () => { const amount = parseFloat(tempAmount); if (!isNaN(amount) && amount > 0) { setFeeConfig({ ...feeConfig, amount }); } setEditing(false); }; const handleCancel = () => { setEditing(false); setTempAmount(feeConfig.amount.toString()); }; const handleTypeChange = (type: FeeType) => { setFeeConfig({ ...feeConfig, type }); }; const platformFee = feeConfig.amount * 0.10; const netAmount = feeConfig.amount - platformFee; const typeLabels: Record = { season: 'Season Fee', monthly: 'Monthly Subscription', per_race: 'Per-Race Fee', }; const typeDescriptions: Record = { season: 'Single payment for entire season', monthly: 'Recurring monthly payment', per_race: 'Payment required per race entry', }; return ( {/* Header */} Membership Fees Charge drivers for league participation {!feeConfig.enabled && !readOnly && ( )} {!feeConfig.enabled ? ( No Membership Fees This league is free to join. Enable membership fees to charge drivers for participation. ) : ( <> {/* Fee Type Selection */} Fee Type {(['season', 'monthly', 'per_race'] as FeeType[]).map((type) => { const FeeIcon = type === 'season' ? Calendar : type === 'monthly' ? TrendingUp : User; const isSelected = feeConfig.type === type; return ( handleTypeChange(type)} disabled={readOnly} p={4} rounded="lg" border transition borderColor={isSelected ? 'border-primary-blue' : 'border-charcoal-outline'} bg={isSelected ? 'bg-primary-blue/10' : 'bg-iron-gray/30'} hoverBorderColor={!isSelected ? 'border-primary-blue/50' : undefined} > {typeLabels[type]} {typeDescriptions[type]} ); })} {/* Amount Configuration */} Amount {editing ? ( ) => setTempAmount(e.target.value)} placeholder="0.00" min="0" step="0.01" /> ) : ( ${feeConfig.amount.toFixed(2)} {typeLabels[feeConfig.type]} {!readOnly && ( )} )} {/* Revenue Breakdown */} {feeConfig.amount > 0 && ( Platform Fee (10%) -${platformFee.toFixed(2)} Net per Driver ${netAmount.toFixed(2)} )} {/* Disable Fees */} {!readOnly && ( )} )} {/* Alpha Notice */} Alpha Note: Membership fee collection is demonstration-only. In production, fees are collected via payment gateway and deposited to league wallet (minus platform fee). ); }