"use client"; import Link from "next/link"; import { useEffect, useMemo, useState } from "react"; import { Header } from "@/components/header"; import { useReveal } from "@/hooks/use-reveal"; import { CellProvenance } from "@/components/provenance-badge"; import { LoadingSkeleton, EmptyState, ErrorState } from "@/components/states"; import { formatSEK, type ProvLevel } from "@/lib/data"; interface CatalogItem { id: string; title: string; markets: string[]; entity_type: string; count: number; updated: string; price_ore: number; confidence: number; } const FILTERS: { key: string; label: string }[] = [ { key: "all", label: "Alla" }, { key: "company", label: "Bolag" }, { key: "contact", label: "Beslutsfattare" }, { key: "vehicle", label: "Fordon" }, { key: "financials", label: "Finansiellt" }, ]; function level(c: number): ProvLevel { if (c >= 0.9) return 3; if (c >= 0.8) return 2; if (c >= 0.5) return 1; return 0; } export default function CatalogPage() { const ref = useReveal(); const [items, setItems] = useState(null); const [err, setErr] = useState(false); const [filter, setFilter] = useState("all"); const [q, setQ] = useState(""); function load() { setErr(false); setItems(null); fetch("/api/catalog") .then((r) => (r.ok ? r.json() : Promise.reject())) .then(setItems) .catch(() => setErr(true)); } useEffect(load, []); const shown = useMemo(() => { if (!items) return []; return items.filter( (d) => (filter === "all" || d.entity_type === filter) && (q === "" || d.title.toLowerCase().includes(q.toLowerCase())), ); }, [items, filter, q]); return (
02

02 — Katalog

Färdig data. Direkt.

{FILTERS.map((f) => ( ))}
setQ(e.target.value)} placeholder="Sök dataset…" className="w-full max-w-xs border border-border bg-input px-3 py-2 font-mono text-xs outline-none focus:border-foreground sm:w-auto" />
{err ? ( ) : items === null ? ( ) : shown.length === 0 ? ( ) : (
{shown.map((d, i) => (

{d.markets.join(" · ")}

{d.title}

{d.count > 0 ? new Intl.NumberFormat("sv-SE").format(d.count) + " poster" : "löpande"} · {d.updated}
{formatSEK(Math.round(d.price_ore / 100))}
Visa → Beställ
))}
)}
); }