'use client'; import { useState } from 'react'; import Button from '../ui/Button'; import Input from '../ui/Input'; import { DollarSign, Calendar, User, TrendingUp } from 'lucide-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({ leagueId, seasonId, 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 */}
{(['season', 'monthly', 'per_race'] as FeeType[]).map((type) => { const Icon = type === 'season' ? Calendar : type === 'monthly' ? TrendingUp : User; const isSelected = feeConfig.type === type; return ( ); })}
{/* Amount Configuration */}
{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).

); }