2026-08-25 07:51:38 +02:00
|
|
|
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
|
|
|
|
|
|
|
|
|
export interface SessionsSummary {
|
|
|
|
|
count: number;
|
|
|
|
|
totalDurationMs: number;
|
|
|
|
|
avgDurationMs: number;
|
|
|
|
|
byKind: { kind: "live" | "replay"; count: number; totalDurationMs: number }[];
|
|
|
|
|
durationPerDevice: { deviceId: number; displayName: string | null; bleName: string; totalActiveMs: number }[];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function formatHours(ms: number): string {
|
|
|
|
|
return `${(ms / 3_600_000).toFixed(1)}h`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function SessionsSummaryCards({ summary }: { summary: SessionsSummary }) {
|
|
|
|
|
const liveCount = summary.byKind.find((k) => k.kind === "live")?.count ?? 0;
|
|
|
|
|
const replayCount = summary.byKind.find((k) => k.kind === "replay")?.count ?? 0;
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="flex flex-col gap-4">
|
|
|
|
|
<div className="grid gap-4 sm:grid-cols-3">
|
|
|
|
|
<Card className="bp-glass">
|
|
|
|
|
<CardHeader>
|
|
|
|
|
<CardTitle className="text-sm text-muted-foreground">Completed sessions</CardTitle>
|
|
|
|
|
</CardHeader>
|
2026-08-25 16:43:28 +02:00
|
|
|
<CardContent className="bp-readout text-3xl">{summary.count}</CardContent>
|
2026-08-25 07:51:38 +02:00
|
|
|
</Card>
|
|
|
|
|
<Card className="bp-glass">
|
|
|
|
|
<CardHeader>
|
|
|
|
|
<CardTitle className="text-sm text-muted-foreground">Total time</CardTitle>
|
|
|
|
|
</CardHeader>
|
2026-08-25 16:43:28 +02:00
|
|
|
<CardContent className="bp-readout text-3xl">{formatHours(summary.totalDurationMs)}</CardContent>
|
2026-08-25 07:51:38 +02:00
|
|
|
</Card>
|
|
|
|
|
<Card className="bp-glass">
|
|
|
|
|
<CardHeader>
|
|
|
|
|
<CardTitle className="text-sm text-muted-foreground">Avg session length</CardTitle>
|
|
|
|
|
</CardHeader>
|
2026-08-25 16:43:28 +02:00
|
|
|
<CardContent className="bp-readout text-3xl">
|
2026-08-25 07:51:38 +02:00
|
|
|
{Math.round(summary.avgDurationMs / 60_000)}m
|
|
|
|
|
</CardContent>
|
|
|
|
|
</Card>
|
|
|
|
|
</div>
|
2026-08-26 18:47:30 +02:00
|
|
|
<Card className="bp-glass">
|
|
|
|
|
<CardContent className="py-3 text-sm text-muted-foreground">
|
|
|
|
|
{liveCount} live · {replayCount} replay
|
|
|
|
|
</CardContent>
|
|
|
|
|
</Card>
|
2026-08-25 07:51:38 +02:00
|
|
|
{summary.durationPerDevice.length > 0 && (
|
|
|
|
|
<Card className="bp-glass">
|
|
|
|
|
<CardHeader>
|
|
|
|
|
<CardTitle className="text-base">Duration per device</CardTitle>
|
|
|
|
|
</CardHeader>
|
|
|
|
|
<CardContent className="flex flex-col gap-2">
|
|
|
|
|
{summary.durationPerDevice.map((d) => (
|
|
|
|
|
<div key={d.deviceId} className="flex items-center justify-between text-sm">
|
|
|
|
|
<span>{d.displayName ?? d.bleName}</span>
|
|
|
|
|
<span className="text-muted-foreground">{formatHours(d.totalActiveMs)}</span>
|
|
|
|
|
</div>
|
|
|
|
|
))}
|
|
|
|
|
</CardContent>
|
|
|
|
|
</Card>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|