"use client" import { useState } from "react" import Link from "next/link" import { useBetslipStore } from "@/lib/store/betslip-store" import { getEventDetailMarkets, getCardsBookingsMarkets, type Event, type DetailMarketSection, } from "@/lib/mock-data" type ApiSection = { id: string; title: string; outcomes: { label: string; odds: number }[] } import { cn } from "@/lib/utils" import { ChevronDown, ChevronUp } from "lucide-react" const MARKET_CATEGORIES = [ "Betbuilder", "All", "Main", "Goals", "Handicap", "1st Half", "2nd Half", "Combo", "Chance Mix", "Home", "Half Time / Full Time", "Away", "Correct Score", "Asian Markets", "Corners", "Minutes", "Cards/Bookings", "Points Handicap", "Total Points", "Team 1", "Team 2", "Other", "Handicap Goals", "Total Goals", "Combo", "Specials", ] function MarketSectionBlock({ section, event, marketName, isExpanded, onToggle, }: { section: DetailMarketSection event: Event marketName: string isExpanded: boolean onToggle: () => void }) { const { bets, addBet } = useBetslipStore() const hasOutcomes = section.outcomes.length > 0 return (
{isExpanded && hasOutcomes && (
{section.outcomes.length > 2 && section.outcomes.length % 2 === 0 ? (
{section.outcomes.map((outcome, i) => { const oddsStr = typeof outcome.odds === "number" ? outcome.odds.toFixed(2) : String(outcome.odds) const betId = `${event.id}-${section.id}-${i}-${outcome.label.replace(/\s/g, "-").toLowerCase()}-${oddsStr}` const isSelected = bets.some((b) => b.id === betId) return (
{outcome.label}
) })}
) : ( section.outcomes.map((outcome, i) => { const oddsStr = typeof outcome.odds === "number" ? outcome.odds.toFixed(2) : String(outcome.odds) const betId = `${event.id}-${section.id}-${i}-${outcome.label.replace(/\s/g, "-").toLowerCase()}-${oddsStr}` const isSelected = bets.some((b) => b.id === betId) return (
{outcome.label}
) }) )}
)}
) } export function MatchDetailView({ event, apiSections, }: { event: Event apiSections?: ApiSection[] | null }) { useBetslipStore((s) => s.bets) const mockDetailMarkets = getEventDetailMarkets(event.id) const cardsBookings = getCardsBookingsMarkets(event.id) const detailMarkets: DetailMarketSection[] = (apiSections?.length ? apiSections.map((s) => ({ id: s.id, title: s.title, outcomes: s.outcomes })) : mockDetailMarkets) as DetailMarketSection[] const [expandedSections, setExpandedSections] = useState>(() => ({ "bookings-1x2": true, "sending-off": true, "1st-booking": true, "1st-half-bookings-1x2": true, "booking-points-ou": true, "1st-half-1st-booking": true, ...(apiSections?.length ? Object.fromEntries(detailMarkets.slice(0, 8).map((s) => [s.id, true])) : {}), })) const [activeCategory, setActiveCategory] = useState("Main") const toggleSection = (id: string) => { setExpandedSections((prev) => ({ ...prev, [id]: !prev[id] })) } const breadcrumbLeague = event.league === "Premier League" ? "England - Premier League" : event.league ? `${event.country} - ${event.league}` : "Event" const isCardsBookings = activeCategory === "Cards/Bookings" const allSections = isCardsBookings ? [...cardsBookings.left, ...cardsBookings.right] : detailMarkets const mid = Math.ceil(allSections.length / 2) const leftSections = allSections.slice(0, mid) const rightSections = allSections.slice(mid) return (
{/* Breadcrumb: back arrow, ellipsis, path */}
< ... Football {breadcrumbLeague} / {event.homeTeam} vs. {event.awayTeam}

{breadcrumbLeague}

{/* Match header: team names in boxes and below */}
{event.homeTeam}
{event.homeTeam}
VS
{event.awayTeam}
{event.awayTeam}
{/* Category tabs: wrap into 2–3 rows, not scrollable */}
{MARKET_CATEGORIES.map((label) => ( ))}
{/* Two-column grid of market sections (split evenly so both columns are used) */}
{/* Left column */}
{leftSections.map((section) => ( toggleSection(section.id)} /> ))}
{/* Right column */}
{rightSections.map((section) => ( toggleSection(section.id)} /> ))}
) }