"use client" import { useEffect } from "react" import Link from "next/link" import { useBetslipStore } from "@/lib/store/betslip-store" import { useLiveStore } from "@/lib/store/live-store" import { SportEnum } from "@/lib/store/betting-types" import { SPORT_ID_MAP } from "@/lib/store/betting-api" import type { AppEvent } from "@/lib/store/betting-types" import { cn } from "@/lib/utils" import { BarChart2, Monitor, Loader2 } from "lucide-react" function LiveEventRow({ event, isNoOdds }: { event: AppEvent; isNoOdds?: boolean }) { const { addBet } = useBetslipStore() const score = event.score ?? "0 - 0" const time = event.matchMinute != null ? `${String(event.matchMinute).padStart(2, "0")}:00` : "—" const period = "H2" return (
{/* Match Info Column (Time & Score) */}
{time} {period}
{event.homeTeam} {score} {event.awayTeam}
{/* Odds Grid or Placeholder */}
{isNoOdds ? (
Sorry, no odds for this match
) : (
{event.markets.slice(0, 3).map((m, idx) => { const labels = ["Home", "Draw", "Away"] return ( ) })}
)}
{/* Right Indicator */}
) } const LIVE_SPORT_IDS = [ SportEnum.SOCCER, SportEnum.BASKETBALL, SportEnum.ICE_HOCKEY, SportEnum.TENNIS, SportEnum.HANDBALL, SportEnum.RUGBY_UNION, SportEnum.TABLE_TENNIS, SportEnum.VOLLEYBALL, SportEnum.FUTSAL, SportEnum.E_SPORTS, ] as const export function LiveEventsList() { const { events, loading, error, sportId, setSportId, loadLiveEvents } = useLiveStore() useEffect(() => { loadLiveEvents() }, [loadLiveEvents]) const groupedByLeague = events.reduce((acc, ev) => { const key = ev.league || "Other" if (!acc[key]) acc[key] = [] acc[key].push(ev) return acc }, {} as Record) return (
{/* Sport Navigation: SportEnum ids, no league — event?sport_id=1&first_start_time=RFC3339&is_live=true */}
{LIVE_SPORT_IDS.map((id) => { const info = SPORT_ID_MAP[id] if (!info) return null const icon = id === SportEnum.SOCCER ? "⚽" : id === SportEnum.TENNIS ? "🎾" : id === SportEnum.BASKETBALL ? "🏀" : id === SportEnum.ICE_HOCKEY ? "🏒" : id === SportEnum.VOLLEYBALL ? "🏐" : id === SportEnum.HANDBALL ? "🤾" : id === SportEnum.E_SPORTS ? "🎮" : "⚽" const active = sportId === id return ( ) })}
{/* Category Header */}
{SPORT_ID_MAP[sportId]?.name === "Soccer" ? "⚽" : "•"}

{SPORT_ID_MAP[sportId]?.name ?? "Live"}

{loading && events.length === 0 ? (
Loading live events…
) : error && events.length === 0 ? (
{error}
) : (
{Object.entries(groupedByLeague).map(([leagueName, matches]) => (
{leagueName}
{matches.map((match) => ( m.odds <= 0)} /> ))}
))}
)}
) }