import { Shield } from "lucide-react"; import { Link } from "react-router"; import { Card, CardContent } from "~/components/ui/card"; import { SectionCardHeader } from "~/components/ui/SectionCardHeader"; import { LeagueRow, type LeagueRowProps } from "./LeagueRow"; const STATUS_ORDER: Record = { draft: 0, active: 1, pre_draft: 2, completed: 3, }; interface MyLeaguesCardProps { leagues: LeagueRowProps[]; viewAllUrl?: string; } export function MyLeaguesCard({ leagues, viewAllUrl }: MyLeaguesCardProps) { const memberLeagues = leagues.filter((l) => !l.isCommishOnly); const commishOnlyLeagues = leagues .filter((l) => l.isCommishOnly) .toSorted((a, b) => a.leagueName.localeCompare(b.leagueName)); const sortedMember = memberLeagues.toSorted((a, b) => { const statusDiff = STATUS_ORDER[a.status] - STATUS_ORDER[b.status]; if (statusDiff !== 0) return statusDiff; if (a.status === "active") { return (b.completionPercentage ?? 0) - (a.completionPercentage ?? 0); } return 0; }); const right = viewAllUrl ? ( View All Leagues ) : undefined; const isEmpty = sortedMember.length === 0 && commishOnlyLeagues.length === 0; return ( {isEmpty ? (

You aren't a member of any leagues yet.

Create your first league →
) : (
{sortedMember.map((league) => ( ))} {commishOnlyLeagues.length > 0 && ( <> {sortedMember.length > 0 &&
}

Leagues I Commish

{commishOnlyLeagues.map((league) => ( ))} )}
)} ); }