export const dynamic = 'force-dynamic'; import { pb, COUNTRY_LABELS, COUNTRY_FLAGS } from "@/lib/pb"; export const metadata = { title: "Meine Sammlung" }; async function getStats() { try { const [gesehen, total] = await Promise.all([ pb.collection("gesehen").getFullList({ fields: "land,datum" }), pb.collection("kennzeichen").getList(1, 1, { filter: "active=true" }), ]); const byCountry: Record = {}; const byMonth: Record = {}; for (const g of gesehen as any[]) { byCountry[g.land] = (byCountry[g.land] ?? 0) + 1; const month = g.datum?.slice(0,7); if (month) byMonth[month] = (byMonth[month] ?? 0) + 1; } return { total: gesehen.length, totalKz: total.totalItems, byCountry, byMonth }; } catch { return { total: 0, totalKz: 0, byCountry: {}, byMonth: {} }; } } async function getLatest() { try { return pb.collection("gesehen").getList(1, 20, { sort: "-datum" }); } catch { return null; } } export default async function SammlungPage() { const [stats, latest] = await Promise.all([getStats(), getLatest()]); const percent = stats.totalKz > 0 ? Math.round((stats.total / stats.totalKz) * 100) : 0; const topCountries = Object.entries(stats.byCountry).sort(([,a],[,b]) => b-a).slice(0,8); const recentMonths = Object.entries(stats.byMonth).sort(([a],[b]) => b.localeCompare(a)).slice(0,6); return (
Persönlich

Meine Sammlung

{stats.total.toLocaleString("de")}
von {stats.totalKz.toLocaleString("de")} Kennzeichen gesehen
{percent}%

Nach Land

{topCountries.map(([country, count]) => (
{COUNTRY_FLAGS[country] ?? "🌍"} {COUNTRY_LABELS[country] ?? country} {count}
))}

AktivitÀt

{recentMonths.map(([month, count]) => { const max = Math.max(...recentMonths.map(([,c]) => c)); return (
{new Date(month+"-01").toLocaleDateString("de-DE",{month:"short",year:"2-digit"})}
{count}
); })}
{latest && latest.items.length > 0 && (

Zuletzt gesehen

{(latest.items as any[]).map((item) => (
{item.kennzeichen_code}
{item.kennzeichen_name} {COUNTRY_FLAGS[item.land] ?? ""}
{new Date(item.datum).toLocaleDateString("de-DE")}
))}
)}
); }