'use client'; import { useState, useEffect } from 'react'; /** * SportSelector — pill tabs for the four launch verticals. * * Soccer reveals a secondary league pill row (WC default for the * tournament launch; EPL/La Liga/etc available year-round). The * selected `{ sport, league }` is emitted via `onChange` so the * parent owns the actual scan/odds state and can refetch on switch. * * The component is intentionally pure-UI — no fetches, no auth, no * persistence. A parent that wants the selection to stick should * pass `initialSport` / `initialLeague` from URL params or * localStorage. */ export type Sport = 'NBA' | 'WNBA' | 'MLB' | 'Soccer'; // Soccer league codes match the GET /api/odds/soccer/:league path // segment AND the `SOCCER_LEAGUES` env on the backend. Source of truth // is `src/services/oddsService.js SOCCER_SPORT_KEYS`. export type SoccerLeague = | 'wc' | 'epl' | 'laliga' | 'bundesliga' | 'seriea' | 'ligue1' | 'ucl' | 'mls' | 'ligamx'; export interface SportSelection { sport: Sport; league?: SoccerLeague; } const SPORTS: Array<{ id: Sport; label: string; status?: 'live' | 'beta' }> = [ { id: 'NBA', label: 'NBA', status: 'live' }, { id: 'WNBA', label: 'WNBA', status: 'live' }, { id: 'MLB', label: 'MLB', status: 'live' }, { id: 'Soccer', label: 'Soccer', status: 'beta' }, ]; const SOCCER_LEAGUES: Array<{ id: SoccerLeague; label: string; sub?: string }> = [ { id: 'wc', label: 'World Cup', sub: '2026' }, { id: 'epl', label: 'EPL' }, { id: 'laliga', label: 'La Liga' }, { id: 'bundesliga', label: 'Bundesliga' }, { id: 'seriea', label: 'Serie A' }, { id: 'ligue1', label: 'Ligue 1' }, { id: 'ucl', label: 'UCL' }, { id: 'mls', label: 'MLS' }, { id: 'ligamx', label: 'Liga MX' }, ]; interface Props { initialSport?: Sport; initialLeague?: SoccerLeague; onChange?: (selection: SportSelection) => void; } export default function SportSelector({ initialSport = 'NBA', initialLeague = 'wc', onChange, }: Props) { const [sport, setSport] = useState(initialSport); const [league, setLeague] = useState(initialLeague); // Emit on every change so parents stay in sync. Effect (not inline // in setSport) so React batches both pieces of state correctly. useEffect(() => { if (onChange) { onChange(sport === 'Soccer' ? { sport, league } : { sport }); } }, [sport, league, onChange]); function selectSport(next: Sport) { setSport(next); } return (
{SPORTS.map((s) => { const active = sport === s.id; return ( ); })}
{sport === 'Soccer' && (
{SOCCER_LEAGUES.map((l) => { const active = league === l.id; return ( ); })}
)}
); }