import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from "@/components/ui/table"; import type { NowPlayingSession } from "../types"; interface Props { sessions: NowPlayingSession[]; emptyMessage?: string; selectedUserLabel?: string; onSelectSession?: (session: NowPlayingSession) => void; } type SessionStateVariant = "success" | "warning" | "secondary"; /** * Map a session state onto a Badge variant per design §2.3. * * `playing` (active/healthy) → `success` (chart-2), `paused` → `warning` * (chart-3), anything else (idle/unknown) → `secondary` (neutral accent). */ function sessionStateVariant(state: string): SessionStateVariant { const normalized = String(state || "") .trim() .toLowerCase(); if (normalized === "playing") return "success"; if (normalized === "paused") return "warning"; return "secondary"; } function formatStateLabel(state: string): string { const normalized = String(state || "") .trim() .toLowerCase(); if (normalized === "playing") { return "Playing"; } if (normalized === "paused") { return "Paused"; } if (normalized === "idle") { return "Idle"; } return normalized ? normalized.charAt(0).toUpperCase() + normalized.slice(1) : "Unknown"; } function buildStatusSummary(sessions: NowPlayingSession[]) { const playing = sessions.filter( (session) => String(session.state || "") .trim() .toLowerCase() === "playing", ).length; const paused = sessions.filter( (session) => String(session.state || "") .trim() .toLowerCase() === "paused", ).length; const idle = sessions.filter( (session) => String(session.state || "") .trim() .toLowerCase() === "idle", ).length; return `${sessions.length} session${sessions.length === 1 ? "" : "s"} · ${playing} playing · ${paused} paused · ${idle} idle`; } export function SessionActivityPanel({ sessions, emptyMessage = "No live sessions matched to this user.", selectedUserLabel, onSelectSession, }: Props) { const userFallback = selectedUserLabel || "Unknown user"; if (!sessions.length) { return

{emptyMessage}

; } return (
User State Title / Type Device Transcoding {onSelectSession ? ( Action ) : null} {buildStatusSummary(sessions)} {sessions.map((session) => { const sessionLabel = formatStateLabel(session.state); return ( onSelectSession(session) : undefined } >
{session.user || userFallback}
{session.session_id}
{sessionLabel}
{session.title || "(idle)"}
{session.type || "—"}
{session.device || "Unknown device"}
{session.transcoding === "yes" ? session.transcoding_type ? `yes (${session.transcoding_type})` : "yes" : "no"} {onSelectSession ? ( ) : null}
); })}
); }