export const dynamic = 'force-dynamic'; import { pb, COUNTRY_LABELS, COUNTRY_FLAGS, type Kennzeichen } from "@/lib/pb"; import KennzeichenFilter from "./KennzeichenFilter"; interface Props { searchParams: { land?: string; q?: string; seite?: string; historisch?: string } } export const metadata = { title: "Datenbank" }; async function getData(land?: string, q?: string, page = 1, historisch = false) { try { const safe = (s: string) => s.replace(/["\\]/g, ""); const filters: string[] = [`country!="global"`]; if (land) filters.push(`country="${safe(land)}"`); if (!historisch) filters.push(`active=true`); if (q) { const s = safe(q); filters.push(`(code~"${s}" || name~"${s}" || region~"${s}")`); } return pb.collection("kennzeichen").getList(page, 100, { filter: filters.join(" && ") || undefined, sort: "code", }); } catch { return null; } } async function getCountryCounts() { try { const all = await pb.collection("kennzeichen").getFullList({ fields: "country", filter: 'active=true && country!="global"' }); const counts: Record = {}; for (const k of all) counts[k.country] = (counts[k.country] ?? 0) + 1; return counts; } catch { return {}; } } function Pagination({ page, totalPages, land, q }: { page: number; totalPages: number; land?: string; q?: string }) { if (totalPages <= 1) return null; const makeHref = (p: number) => { const params = new URLSearchParams(); if (land) params.set("land", land); if (q) params.set("q", q); params.set("seite", String(p)); return `?${params.toString()}`; }; const pages: (number | string)[] = []; for (let p = 1; p <= totalPages; p++) { if (p === 1 || p === totalPages || Math.abs(p - page) <= 2) { pages.push(p); } else if (pages[pages.length - 1] !== "…") { pages.push("…"); } } return (
{page > 1 && ( )} {pages.map((p, i) => p === "…" ? ( ) : ( {p} ) )} {page < totalPages && ( )}
); } export default async function KennzeichenPage({ searchParams }: Props) { const land = searchParams.land; const q = searchParams.q; const page = parseInt(searchParams.seite ?? "1"); const historisch = searchParams.historisch === "1"; const [data, counts] = await Promise.all([getData(land, q, page, historisch), getCountryCounts()]); const items = data?.items ?? []; return (
Datenbank

Kennzeichen

{data &&

{data.totalItems.toLocaleString("de")} Einträge

}
({ key, label, flag: COUNTRY_FLAGS[key] ?? "🌍", count: counts[key] ?? 0 }))} activeLand={land} activeQ={q} historisch={historisch} />
{items.length === 0 ? (
Keine Kennzeichen gefunden.
) : (
{items.map((kz) => ( ))}
KürzelOrt / KreisHerleitung Region Punkte Bemerkung
{kz.code} {kz.name} {kz.derivation} {kz.region} {kz.points ?? "—"} {kz.note}
)}
{data && }
); }