import Link from "next/link" import { CalendarDays, ChevronRight, Flag, Gauge, MapPin, Medal, Trophy, Users } from "lucide-react" import { cn } from "@/lib/utils" export type RoundStatus = "active" | "completed" export type Round = { id: string name?: string | null courseName: string status: RoundStatus teeName: string holes: 9 | 18 date: string playerCount: number // Progress for rounds still in play. holesPlayed?: number // Owner's score, present once at least one hole is recorded. totalScore?: number toPar?: number // Handicap differential, only when a completed round counted (one decimal). differential?: number | null // Lowest score-to-par among the viewer's own completed rounds (computed // by the caller across the full rounds list, not by the card itself). isPersonalBest?: boolean } const STATUS_CONFIG: Record = { active: { label: "Pågår", dot: "bg-primary", badge: "bg-primary/15 text-foreground", }, completed: { label: "Fullført", dot: "bg-brand-orange", badge: "bg-brand-orange/12 text-foreground", }, } const dateFormatter = new Intl.DateTimeFormat("no-NO", { day: "numeric", month: "short", year: "numeric", }) function formatDate(value: string) { const parsed = new Date(value) if (Number.isNaN(parsed.getTime())) return value return dateFormatter.format(parsed) } // "+10", "-2" or "E" for level par. The sign carries the meaning (never color alone). function formatToPar(toPar: number) { if (toPar === 0) return "E" return toPar > 0 ? `+${toPar}` : `${toPar}` } function toParDescription(toPar: number) { if (toPar === 0) return "på par" return toPar > 0 ? `${toPar} over par` : `${Math.abs(toPar)} under par` } function RoundStatusBadge({ status }: { status: RoundStatus }) { const config = STATUS_CONFIG[status] return ( ) } // Prominent right-side tile: final score for completed/scored rounds, // hole progress for rounds still in play. function ScoreTile({ round }: { round: Round }) { const hasScore = typeof round.totalScore === "number" && typeof round.toPar === "number" if (round.status === "active" || !hasScore) { const played = round.holesPlayed ?? 0 const pct = round.holes > 0 ? Math.min(100, Math.round((played / round.holes) * 100)) : 0 return (
{played} /{round.holes} hull spilt
) } const toPar = round.toPar as number const overPar = toPar > 0 const underPar = toPar < 0 return (
{round.totalScore} {formatToPar(toPar)} til par
) } export function RoundCard({ round }: { round: Round }) { const playerLabel = round.playerCount === 1 ? "spiller" : "spillere" const hasScore = typeof round.totalScore === "number" && typeof round.toPar === "number" const showDifferential = round.status === "completed" && typeof round.differential === "number" && round.differential !== null const differentialText = showDifferential && round.differential != null ? round.differential.toFixed(1).replace(".", ",") : null const showPersonalBest = round.status === "completed" && round.isPersonalBest === true // Concise summary so the compact score tile reads clearly for screen readers. const scoreSummary = round.status === "completed" && hasScore ? `Resultat ${round.totalScore} slag, ${toParDescription(round.toPar as number)}.` : `${round.holesPlayed ?? 0} av ${round.holes} hull spilt.` const displayTitle = round.name?.trim() || round.courseName const ariaLabel = `${displayTitle}, ${STATUS_CONFIG[round.status].label}. ${scoreSummary}` return ( // Egen ytre wrapper (2026-07-26) -- kortet var tidligere HELE selve // lenken til rundesiden; en leaderboard-lenke kan derfor ikke ligge // NESTET inni den (ugyldig HTML, samme klasse feil som tidligere // nestede-form-/knapp-feller i prosjektet). Hovedinnholdet er fortsatt // én stor lenke til rundesiden, leaderboard-lenken en egen, separat // rad under.

{showPersonalBest && ( )}
{round.name?.trim() && {round.courseName}} {differentialText && ( )}
) }