Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 | import React from 'react'; import { Link } from 'react-router-dom'; import OddsCell, { EmptyOddsCell } from './OddsCell'; import { formatTime, getSportDisplayName, getSportColorClass } from '../../utils/format'; interface GameOdds { spread?: { line: number; odds: number }; total?: { line: number; odds: number }; moneyline?: number; } interface Game { id: string; sportKey: string; sportName: string; awayTeamName: string; homeTeamName: string; commenceTime: string; venue?: string; weather?: string; status: string; homeScore?: number | null; awayScore?: number | null; awayOdds?: GameOdds; homeOdds?: GameOdds; period?: string | null; clock?: string | null; } interface Selection { gameId: string; selectionType: 'moneyline' | 'spread' | 'total'; selection: 'home' | 'away' | 'over' | 'under'; odds: number; line?: number; gameName: string; teamName?: string; } interface GameCardProps { game: Game; onSelect: (selection: Selection) => void; selectedBets?: Set<string>; useDecimalOdds?: boolean; bookmaker?: string; } export default function GameCard({ game, onSelect, selectedBets = new Set(), useDecimalOdds = false, bookmaker = 'draftkings' }: GameCardProps) { const isLive = game.status === 'in_progress'; const isCompleted = game.status === 'final'; const sportBadge = getSportDisplayName(game.sportKey); const sportColor = getSportColorClass(game.sportKey); // Get bookmaker display name and logo const getBookmakerInfo = (bookmakerKey: string) => { const bookmakers: Record<string, {name: string, logo: string, color: string}> = { draftkings: { name: 'DraftKings', logo: '👑', color: 'bg-green-600' }, fanduel: { name: 'FanDuel', logo: '🎯', color: 'bg-blue-600' }, betmgm: { name: 'BetMGM', logo: '🦁', color: 'bg-yellow-600' }, pointsbet: { name: 'PointsBet', logo: '⚡', color: 'bg-red-600' }, bovada: { name: 'Bovada', logo: '🐂', color: 'bg-red-700' }, mybookie: { name: 'MyBookie', logo: '📚', color: 'bg-purple-600' }, }; return bookmakers[bookmakerKey] || { name: bookmakerKey, logo: '🎲', color: 'bg-gray-600' }; }; const bookmakerInfo = getBookmakerInfo(bookmaker); // Helper to generate selection key const getSelectionKey = ( selectionType: string, selection: string, line?: number ): string => { return `${game.id}-${selectionType}-${selection}${line !== undefined ? `-${line}` : ''}`; }; // Helper to check if selection is active const isSelected = (selectionType: string, selection: string, line?: number): boolean => { return selectedBets.has(getSelectionKey(selectionType, selection, line)); }; // Handler for moneyline selection const handleMoneylineClick = (selection: 'home' | 'away', odds: number) => { onSelect({ gameId: game.id, selectionType: 'moneyline', selection, odds, gameName: `${game.awayTeamName} vs ${game.homeTeamName}`, teamName: selection === 'home' ? game.homeTeamName : game.awayTeamName }); }; // Handler for spread selection const handleSpreadClick = ( selection: 'home' | 'away', odds: number, line: number ) => { onSelect({ gameId: game.id, selectionType: 'spread', selection, odds, line, gameName: `${game.awayTeamName} vs ${game.homeTeamName}`, teamName: selection === 'home' ? game.homeTeamName : game.awayTeamName }); }; // Handler for total selection const handleTotalClick = ( selection: 'over' | 'under', odds: number, line: number ) => { onSelect({ gameId: game.id, selectionType: 'total', selection, odds, line, gameName: `${game.awayTeamName} vs ${game.homeTeamName}` }); }; return ( <div className="bg-white dark:bg-gray-800 rounded-lg shadow-md overflow-hidden hover:shadow-lg transition-shadow"> {/* Game Header */} <div className="bg-gray-50 dark:bg-gray-700 px-4 py-2 border-b border-gray-200 dark:border-gray-600"> <div className="flex items-center justify-between mb-2"> <div className="flex items-center gap-2"> <span className={`${sportColor} text-white text-xs font-bold px-2 py-1 rounded`}> {sportBadge} </span> <span className="text-sm text-gray-600 dark:text-gray-300"> {formatTime(game.commenceTime)} </span> {isLive && ( <div className="flex items-center gap-1"> <span className="bg-red-500 text-white text-xs font-bold px-2 py-1 rounded animate-pulse"> LIVE </span> {(game.period || game.clock) && ( <span className="text-xs text-gray-600 dark:text-gray-300"> {game.period && <span>{game.period}</span>} {game.clock && <span className="ml-1">{game.clock}</span>} </span> )} </div> )} </div> <div className={`${bookmakerInfo.color} text-white text-xs font-bold px-2 py-1 rounded flex items-center gap-1`}> <span>{bookmakerInfo.logo}</span> <span>{bookmakerInfo.name}</span> </div> </div> {/* Game Location/Weather Info */} <div className="flex items-center justify-between text-xs text-gray-500 dark:text-gray-400"> <div> <span>📍 {game.venue || `${game.homeTeamName} Home`}</span> {game.weather && ( <span className="ml-3">🌤️ {game.weather}</span> )} {!game.weather && game.sportKey.includes('basketball') && ( <span className="ml-3">🏀 Indoor Arena</span> )} {!game.weather && game.sportKey.includes('hockey') && ( <span className="ml-3">🏒 Indoor Arena</span> )} </div> <Link to={`/game/${game.id}`} className="text-blue-500 hover:text-blue-400 transition-colors flex items-center gap-1 font-medium" > View Stats <svg className="w-3 h-3" fill="none" stroke="currentColor" viewBox="0 0 24 24"> <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M9 5l7 7-7 7" /> </svg> </Link> </div> </div> {/* Column Headers - Only show for active games */} {!isCompleted && ( <div className="grid grid-cols-[2fr_repeat(3,1fr)] gap-2 px-4 py-2 bg-gray-100 dark:bg-gray-700 text-xs font-semibold text-gray-600 dark:text-gray-300"> <div>Team</div> <div className="text-center">Spread</div> <div className="text-center">Total</div> <div className="text-center">Moneyline</div> </div> )} {/* Final Score Header for completed games */} {isCompleted && ( <div className="px-4 py-2 bg-gray-100 dark:bg-gray-700 text-xs font-semibold text-gray-600 dark:text-gray-300 text-center"> Final Score </div> )} {/* Away Team Row */} {!isCompleted ? ( <div className="grid grid-cols-[2fr_repeat(3,1fr)] gap-2 px-4 py-3 border-b border-gray-100 dark:border-gray-700 items-center"> <div className="flex items-center justify-between"> <div> <Link to={`/teams/${encodeURIComponent(game.sportKey)}/${encodeURIComponent(game.awayTeamName)}`} className="font-medium text-gray-900 dark:text-white hover:text-blue-600 dark:hover:text-blue-400 transition-colors" > {game.awayTeamName} </Link> <div className="text-xs text-gray-500 dark:text-gray-400 uppercase">Away</div> </div> {isLive && game.awayScore !== null && game.awayScore !== undefined && ( <span className="text-2xl font-bold text-blue-600 dark:text-blue-400"> {game.awayScore} </span> )} </div> <div className="flex justify-center"> {game.awayOdds?.spread ? ( <OddsCell odds={game.awayOdds.spread.odds} line={game.awayOdds.spread.line} selected={isSelected('spread', 'away', game.awayOdds.spread.line)} onClick={() => handleSpreadClick('away', game.awayOdds.spread!.odds, game.awayOdds.spread!.line) } useDecimalOdds={useDecimalOdds} /> ) : ( <EmptyOddsCell /> )} </div> <div className="flex justify-center"> {game.awayOdds?.total ? ( <OddsCell odds={game.awayOdds.total.odds} line={game.awayOdds.total.line} prefix="O" selected={isSelected('total', 'over', game.awayOdds.total.line)} onClick={() => handleTotalClick('over', game.awayOdds.total!.odds, game.awayOdds.total!.line) } useDecimalOdds={useDecimalOdds} /> ) : ( <EmptyOddsCell /> )} </div> <div className="flex justify-center"> {game.awayOdds?.moneyline ? ( <OddsCell odds={game.awayOdds.moneyline} selected={isSelected('moneyline', 'away')} onClick={() => handleMoneylineClick('away', game.awayOdds.moneyline!)} useDecimalOdds={useDecimalOdds} /> ) : ( <EmptyOddsCell /> )} </div> </div> ) : ( <div className="flex items-center justify-between px-4 py-3 border-b border-gray-200 dark:border-gray-700"> <div> <div className="font-medium text-gray-900 dark:text-white">{game.awayTeamName}</div> <div className="text-xs text-gray-500 dark:text-gray-400 uppercase">Away</div> </div> <span className="text-3xl font-bold text-gray-900 dark:text-gray-100"> {game.awayScore ?? '-'} </span> </div> )} {/* Home Team Row */} {!isCompleted ? ( <div className="grid grid-cols-[2fr_repeat(3,1fr)] gap-2 px-4 py-3 items-center"> <div className="flex items-center justify-between"> <div> <Link to={`/teams/${encodeURIComponent(game.sportKey)}/${encodeURIComponent(game.homeTeamName)}`} className="font-medium text-gray-900 dark:text-white hover:text-blue-600 dark:hover:text-blue-400 transition-colors" > {game.homeTeamName} </Link> <div className="text-xs text-gray-500 dark:text-gray-400 uppercase">Home</div> </div> {isLive && game.homeScore !== null && game.homeScore !== undefined && ( <span className="text-2xl font-bold text-blue-600 dark:text-blue-400"> {game.homeScore} </span> )} </div> <div className="flex justify-center"> {game.homeOdds?.spread ? ( <OddsCell odds={game.homeOdds.spread.odds} line={game.homeOdds.spread.line} selected={isSelected('spread', 'home', game.homeOdds.spread.line)} onClick={() => handleSpreadClick('home', game.homeOdds.spread!.odds, game.homeOdds.spread!.line) } useDecimalOdds={useDecimalOdds} /> ) : ( <EmptyOddsCell /> )} </div> <div className="flex justify-center"> {game.homeOdds?.total ? ( <OddsCell odds={game.homeOdds.total.odds} line={game.homeOdds.total.line} prefix="U" selected={isSelected('total', 'under', game.homeOdds.total.line)} onClick={() => handleTotalClick('under', game.homeOdds.total!.odds, game.homeOdds.total!.line) } useDecimalOdds={useDecimalOdds} /> ) : ( <EmptyOddsCell /> )} </div> <div className="flex justify-center"> {game.homeOdds?.moneyline ? ( <OddsCell odds={game.homeOdds.moneyline} selected={isSelected('moneyline', 'home')} onClick={() => handleMoneylineClick('home', game.homeOdds.moneyline!)} useDecimalOdds={useDecimalOdds} /> ) : ( <EmptyOddsCell /> )} </div> </div> ) : ( <div className="flex items-center justify-between px-4 py-3"> <div> <Link to={`/teams/${encodeURIComponent(game.sportKey)}/${encodeURIComponent(game.homeTeamName)}`} className="font-medium text-gray-900 dark:text-white hover:text-blue-600 dark:hover:text-blue-400 transition-colors" > {game.homeTeamName} </Link> <div className="text-xs text-gray-500 dark:text-gray-400 uppercase">Home</div> </div> <span className="text-3xl font-bold text-gray-900 dark:text-gray-100"> {game.homeScore ?? '-'} </span> </div> )} </div> ); } |