'use client'; import { useMemo, useState } from 'react'; import { BookmakerCode, generateBetSlipUrl } from '@/lib/betting-utils'; const logoMap: Record = { bet365: 'Bet365', pinnacle: 'Pinnacle', draftkings: 'DraftKings', }; type 球員道具盤 = { bookmakerId: BookmakerCode; matchId: string; selection: string; odds: number; disabled?: boolean; }; export function QuickBetButton({ bookmakerId, matchId, selection, odds, disabled = false }: 球員道具盤) { const [isRedirecting, setIsRedirecting] = useState(false); const label = logoMap[bookmakerId]; const oddsText = odds.toFixed(2); const href = useMemo( () => generateBetSlipUrl({ bookmakerId, matchId, selection, odds, }), [bookmakerId, matchId, selection, odds], ); const isUnavailable = disabled || !href; const handleClick = () => { if (disabled || !href) { return; } setIsRedirecting(true); window.open(href, '_blank', 'noopener,noreferrer'); window.setTimeout(() => setIsRedirecting(false), 900); }; return ( ); }