import { formatDistanceToNow } from "date-fns";
import { Link } from "react-router";
import { Button } from "~/components/ui/button";
import { LeagueAvatar } from "./LeagueAvatar";
export interface LeagueRowProps {
leagueId: string;
leagueName: string;
numSports: number;
status: "draft" | "active" | "pre_draft" | "completed";
seasonId?: string;
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"}`;
}
// ─── Shared stat column ───────────────────────────────────────────────────────
function StatColumn({
label,
children,
}: {
label: string;
children: React.ReactNode;
}) {
return (
);
}
function StatDivider() {
return ;
}
// ─── 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 (
);
}
// ─── Rank change indicator ────────────────────────────────────────────────────
function RankChange({ current, previous }: { current: number; previous: number | undefined }) {
if (previous === undefined || previous === current) return null;
const delta = previous - current;
if (delta > 0) {
return ▲{delta};
}
return (
▼{Math.abs(delta)}
);
}
// ─── 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,
currentRank,
totalPoints,
previousRank,
completionPercentage = 0,
}: LeagueRowProps) {
const showStats = currentRank !== undefined || totalPoints !== undefined;
return (
{/* Avatar + name */}
{/* Stats — second row on mobile, right side on desktop */}
{showStats && (
{currentRank !== undefined && (
#{currentRank}
)}
{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 */}
{/* Stats — second row on mobile, right side on desktop */}
{draftTimeValue}
{draftPosition !== undefined && (
<>
{ordinal(draftPosition)}
>
)}
);
}
function CompletedRow({
leagueId,
leagueName,
completionPercentage = 0,
}: LeagueRowProps) {
return (
);
}
// ─── Public export ────────────────────────────────────────────────────────────
export function LeagueRow(props: LeagueRowProps) {
if (props.status === "draft") return ;
if (props.status === "active") return ;
if (props.status === "pre_draft") return ;
return ;
}