import { formatDistanceToNow } from "date-fns"; import { Link } from "react-router"; import { Button } from "~/components/ui/button"; import { LeagueAvatar } from "./LeagueAvatar"; import { StatColumn, StatDivider, RankingDisplay } from "./StatHelpers"; export interface LeagueRowProps { leagueId: string; leagueName: string; numSports: number; status: "draft" | "active" | "pre_draft" | "completed"; seasonId?: string; displayRank?: string | number; currentRank?: number; totalPoints?: number; previousRank?: number; completionPercentage?: number; draftDateTime?: string | null; picksUntilMyTurn?: number; draftPosition?: number; } // ─── Helpers ────────────────────────────────────────────────────────────────── function ordinal(n: number): string { const v = n % 100; // 11–13 are always "th" (e.g. 11th, 12th, 13th) if (v >= 11 && v <= 13) return `${n}th`; const s = ["th", "st", "nd", "rd"]; return `${n}${s[n % 10] ?? "th"}`; } // ─── Season progress bar ────────────────────────────────────────────────────── function SeasonProgress({ pct, status }: { pct: number; status: "active" | "completed" }) { const label = status === "completed" ? "100% Complete" : `${pct}% Complete`; const fill = status === "completed" ? 100 : pct; return (
{label}
); } // ─── Row variants ───────────────────────────────────────────────────────────── function DraftRow({ leagueId, leagueName, seasonId, picksUntilMyTurn }: LeagueRowProps) { const draftUrl = `/leagues/${leagueId}/draft/${seasonId}`; const picksLabel = picksUntilMyTurn === 0 ? "You're on the clock!" : picksUntilMyTurn !== undefined ? `Up in ${picksUntilMyTurn} pick${picksUntilMyTurn === 1 ? "" : "s"}` : null; return (

{leagueName}

Draft in Progress
{picksLabel && ( {picksLabel} )}
{seasonId && ( )}
{seasonId && ( )}
); } function ActiveRow({ leagueId, leagueName, displayRank, currentRank, totalPoints, previousRank, completionPercentage = 0, }: LeagueRowProps) { const showStats = currentRank !== undefined || totalPoints !== undefined; return ( {/* Avatar + name */}

{leagueName}

{/* Stats — second row on mobile, right side on desktop */} {showStats && (
{displayRank !== undefined && ( )} {currentRank !== undefined && totalPoints !== undefined && } {totalPoints !== undefined && ( {Math.round(totalPoints).toLocaleString("en-US")} )}
)} ); } function PreDraftRow({ leagueId, leagueName, draftDateTime, draftPosition, }: LeagueRowProps) { let draftTimeValue = "Not scheduled"; if (draftDateTime) { const draftDate = new Date(draftDateTime); draftTimeValue = draftDate > new Date() ? formatDistanceToNow(draftDate, { addSuffix: true }) : "Starting soon"; } return ( {/* Avatar + name */}

{leagueName}

Pre-Draft

{/* Stats — second row on mobile, right side on desktop */}
{draftTimeValue} {draftPosition !== undefined && ( <> {ordinal(draftPosition)} )}
); } function CompletedRow({ leagueId, leagueName, completionPercentage = 0, }: LeagueRowProps) { return (

{leagueName}

); } // ─── Public export ──────────────────────────────────────────────────────────── export function LeagueRow(props: LeagueRowProps) { if (props.status === "draft") return ; if (props.status === "active") return ; if (props.status === "pre_draft") return ; return ; }