import { Users } from "lucide-react"; import { GradientIcon } from "~/components/ui/GradientIcon"; // ─── Types ──────────────────────────────────────────────────────────────────── export interface TeamsPanelProps { teams: Array<{ id: string; name: string; ownerId: string | null }>; currentUserId: string | null; /** Maps userId → display name */ ownerMap: Record; /** When non-empty, sorts all teams in draft order and shows position numbers */ draftSlots: Array<{ team: { id: string } }>; } // ─── Public API ─────────────────────────────────────────────────────────────── export function TeamsPanel({ teams, currentUserId, ownerMap, draftSlots }: TeamsPanelProps) { const hasDraftOrder = draftSlots.length > 0; const claimedCount = teams.filter((t) => t.ownerId !== null).length; const isFull = claimedCount === teams.length; const fillPercent = teams.length > 0 ? Math.round((claimedCount / teams.length) * 100) : 0; const displayTeams = hasDraftOrder ? (() => { const orderMap = new Map(draftSlots.map((s, i) => [s.team.id, i])); return teams.toSorted( (a, b) => (orderMap.get(a.id) ?? Infinity) - (orderMap.get(b.id) ?? Infinity) ); })() : teams.filter((t) => t.ownerId !== null); const showProgressBar = !(hasDraftOrder && isFull); return (
{hasDraftOrder ? "Draft Order" : "Teams"}
{showProgressBar && (
Filled {claimedCount} / {teams.length}
)}
{displayTeams.map((team, index) => { const isOwned = team.ownerId === currentUserId; const ownerName = team.ownerId ? ownerMap[team.ownerId] : null; return (
{hasDraftOrder && ( {index + 1} )}

{team.name}

{team.ownerId ? isOwned ? You : {ownerName || "Unknown"} : }

); })}
); }