2025-10-20 15:03:11 -07:00
|
|
|
import { Card } from "~/components/ui/card";
|
|
|
|
|
import {
|
|
|
|
|
ContextMenu,
|
|
|
|
|
ContextMenuContent,
|
|
|
|
|
ContextMenuItem,
|
|
|
|
|
ContextMenuTrigger,
|
|
|
|
|
} from "~/components/ui/context-menu";
|
|
|
|
|
|
|
|
|
|
interface DraftGridProps {
|
|
|
|
|
draftSlots: Array<{
|
|
|
|
|
id: string;
|
|
|
|
|
draftOrder: number;
|
|
|
|
|
team: {
|
|
|
|
|
id: string;
|
|
|
|
|
name: string;
|
|
|
|
|
};
|
|
|
|
|
}>;
|
|
|
|
|
draftGrid: any[][];
|
|
|
|
|
currentPick: number;
|
|
|
|
|
teamTimers?: Record<string, number>;
|
|
|
|
|
formatTime?: (seconds: number | undefined) => string;
|
|
|
|
|
title?: string;
|
|
|
|
|
isCommissioner?: boolean;
|
|
|
|
|
onForceAutopick?: (pickNumber: number, teamId: string) => void;
|
|
|
|
|
onForceManualPick?: (pickNumber: number, teamId: string) => void;
|
2025-10-21 23:22:17 -07:00
|
|
|
autodraftStatus?: Record<string, boolean>;
|
|
|
|
|
connectedTeams?: Set<string>;
|
2026-02-22 16:56:07 -08:00
|
|
|
ownerMap?: Record<string, string>;
|
2025-10-20 15:03:11 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function DraftGrid({
|
|
|
|
|
draftSlots,
|
|
|
|
|
draftGrid,
|
|
|
|
|
currentPick,
|
|
|
|
|
teamTimers,
|
|
|
|
|
formatTime,
|
|
|
|
|
title,
|
|
|
|
|
isCommissioner = false,
|
|
|
|
|
onForceAutopick,
|
|
|
|
|
onForceManualPick,
|
2025-10-21 23:22:17 -07:00
|
|
|
autodraftStatus = {},
|
|
|
|
|
connectedTeams = new Set(),
|
2026-02-22 16:56:07 -08:00
|
|
|
ownerMap = {},
|
2025-10-20 15:03:11 -07:00
|
|
|
}: DraftGridProps) {
|
|
|
|
|
const totalTeams = draftSlots.length;
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Card className="p-4">
|
|
|
|
|
{title && <h2 className="text-xl font-semibold mb-4">{title}</h2>}
|
|
|
|
|
<div className="w-full">
|
2025-10-21 23:22:17 -07:00
|
|
|
{/* Team Headers */}
|
|
|
|
|
<div className="flex gap-2 mb-2">
|
|
|
|
|
{draftSlots.map((slot) => {
|
|
|
|
|
const teamTime = teamTimers?.[slot.team.id];
|
|
|
|
|
const isAutodraft = autodraftStatus[slot.team.id] || false;
|
|
|
|
|
const isConnected = connectedTeams.has(slot.team.id);
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div key={slot.id} className="flex-1 min-w-32 text-center">
|
|
|
|
|
<div
|
|
|
|
|
className={`font-semibold text-sm truncate px-2 ${!isConnected ? "italic text-muted-foreground" : ""}`}
|
|
|
|
|
>
|
2026-02-22 16:56:07 -08:00
|
|
|
{ownerMap[slot.team.id] || slot.team.name}
|
2025-10-21 23:22:17 -07:00
|
|
|
</div>
|
|
|
|
|
{teamTimers && formatTime && (
|
|
|
|
|
<div
|
|
|
|
|
className={`text-xs font-mono ${
|
|
|
|
|
teamTime === undefined
|
|
|
|
|
? "text-muted-foreground"
|
|
|
|
|
: teamTime > 60
|
2026-02-20 19:26:11 -08:00
|
|
|
? "text-emerald-400"
|
2025-10-20 15:03:11 -07:00
|
|
|
: teamTime > 30
|
2026-02-20 19:26:11 -08:00
|
|
|
? "text-amber-accent"
|
|
|
|
|
: "text-coral-accent"
|
2025-10-21 23:22:17 -07:00
|
|
|
}`}
|
|
|
|
|
>
|
|
|
|
|
{formatTime(teamTime)}
|
|
|
|
|
{isAutodraft && (
|
|
|
|
|
<span className="ml-1 text-muted-foreground">(auto)</span>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
})}
|
|
|
|
|
</div>
|
2025-10-20 15:03:11 -07:00
|
|
|
|
2025-10-21 23:22:17 -07:00
|
|
|
{/* Draft Grid Rows */}
|
|
|
|
|
<div className="space-y-2">
|
|
|
|
|
{draftGrid.map((roundPicks, roundIndex) => {
|
|
|
|
|
const round = roundIndex + 1;
|
|
|
|
|
const isEvenRound = round % 2 === 0;
|
|
|
|
|
const displayPicks = isEvenRound
|
|
|
|
|
? [...roundPicks].reverse()
|
|
|
|
|
: roundPicks;
|
2025-10-20 15:03:11 -07:00
|
|
|
|
2025-10-21 23:22:17 -07:00
|
|
|
return (
|
|
|
|
|
<div key={roundIndex} className="flex gap-2">
|
|
|
|
|
{displayPicks.map((cell, index) => {
|
|
|
|
|
const actualIndex = isEvenRound
|
|
|
|
|
? roundPicks.length - 1 - index
|
|
|
|
|
: index;
|
|
|
|
|
const slot = draftSlots[actualIndex];
|
|
|
|
|
const pickNumber = roundIndex * totalTeams + actualIndex + 1;
|
|
|
|
|
const isCurrent = pickNumber === currentPick;
|
|
|
|
|
const isPicked = !!cell;
|
2025-10-20 15:03:11 -07:00
|
|
|
|
2025-10-21 23:22:17 -07:00
|
|
|
const cellContent = (
|
|
|
|
|
<div
|
|
|
|
|
className={`flex-1 min-w-0 h-20 border-2 rounded-lg p-2 transition-all ${
|
2025-10-24 21:25:02 -07:00
|
|
|
isPicked
|
2026-02-20 19:26:11 -08:00
|
|
|
? "bg-emerald-500/10 border-emerald-500/30"
|
2025-10-24 21:25:02 -07:00
|
|
|
: isCurrent
|
2026-02-20 19:26:11 -08:00
|
|
|
? "border-electric bg-electric/15 shadow-lg shadow-electric/10"
|
|
|
|
|
: "border-border bg-card"
|
2025-10-21 23:22:17 -07:00
|
|
|
}`}
|
|
|
|
|
title={`Overall Pick #${pickNumber}`}
|
|
|
|
|
>
|
|
|
|
|
<div className="text-xs font-mono text-muted-foreground mb-1">
|
|
|
|
|
{round}.{String(actualIndex + 1).padStart(2, "0")}
|
|
|
|
|
</div>
|
|
|
|
|
{isPicked ? (
|
|
|
|
|
<div className="text-xs">
|
|
|
|
|
<div className="font-semibold truncate">
|
|
|
|
|
{cell.participant.name}
|
2025-10-20 15:03:11 -07:00
|
|
|
</div>
|
2025-10-21 23:22:17 -07:00
|
|
|
<div className="text-muted-foreground truncate">
|
|
|
|
|
{cell.sport.name}
|
2025-10-20 15:03:11 -07:00
|
|
|
</div>
|
2025-10-21 23:22:17 -07:00
|
|
|
</div>
|
|
|
|
|
) : isCurrent ? (
|
2026-02-20 19:26:11 -08:00
|
|
|
<div className="text-xs font-semibold text-electric">
|
2025-10-21 23:22:17 -07:00
|
|
|
On Clock
|
|
|
|
|
</div>
|
|
|
|
|
) : null}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
2025-10-20 15:03:11 -07:00
|
|
|
|
2025-10-21 23:22:17 -07:00
|
|
|
// Wrap with context menu if commissioner and current unpicked cell
|
|
|
|
|
if (
|
|
|
|
|
isCommissioner &&
|
|
|
|
|
!isPicked &&
|
|
|
|
|
isCurrent &&
|
|
|
|
|
onForceAutopick &&
|
|
|
|
|
onForceManualPick
|
|
|
|
|
) {
|
|
|
|
|
return (
|
|
|
|
|
<ContextMenu key={pickNumber}>
|
|
|
|
|
<ContextMenuTrigger asChild>
|
|
|
|
|
{cellContent}
|
|
|
|
|
</ContextMenuTrigger>
|
|
|
|
|
<ContextMenuContent>
|
|
|
|
|
<ContextMenuItem
|
|
|
|
|
onClick={() =>
|
|
|
|
|
onForceAutopick(pickNumber, slot.team.id)
|
|
|
|
|
}
|
|
|
|
|
>
|
|
|
|
|
Force Auto Pick
|
|
|
|
|
</ContextMenuItem>
|
|
|
|
|
<ContextMenuItem
|
|
|
|
|
onClick={() =>
|
|
|
|
|
onForceManualPick(pickNumber, slot.team.id)
|
|
|
|
|
}
|
|
|
|
|
>
|
|
|
|
|
Force Manual Pick
|
|
|
|
|
</ContextMenuItem>
|
|
|
|
|
</ContextMenuContent>
|
|
|
|
|
</ContextMenu>
|
|
|
|
|
);
|
|
|
|
|
}
|
2025-10-20 15:03:11 -07:00
|
|
|
|
2025-10-21 23:22:17 -07:00
|
|
|
return cellContent;
|
|
|
|
|
})}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
})}
|
|
|
|
|
</div>
|
2025-10-20 15:03:11 -07:00
|
|
|
</div>
|
|
|
|
|
</Card>
|
|
|
|
|
);
|
|
|
|
|
}
|