fix(recovery): restore source removed by production documentation merge

This commit is contained in:
2026-11-10 03:42:10 +01:00
parent 585bdd4b44
commit 3d2fc6f913
957 changed files with 115754 additions and 0 deletions
+296
View File
@@ -0,0 +1,296 @@
"use client";
import Link from "next/link";
import { useParams, useSearchParams } from "next/navigation";
import { useEffect, useRef, useState } from "react";
import { toast } from "sonner";
import { OrderStepper } from "@/components/order-stepper";
import { useT } from "@/components/locale-provider";
import { useReveal } from "@/hooks/use-reveal";
import { getLocalOrder } from "@/lib/order-client";
const STAGES: { key: string; title: { en: string; sv: string }; meta: { en: string; sv: string } }[] = [
{ key: "source", title: { en: "Source race", sv: "Källracing" }, meta: { en: "GLEIF · Brreg · CVR · PRH", sv: "GLEIF · Brreg · CVR · PRH" } },
{ key: "extract", title: { en: "Extraction & OCR", sv: "Extraktion & OCR" }, meta: { en: "register-API · documents", sv: "register-API · dokument" } },
{ key: "structure", title: { en: "Structuring & matching", sv: "Strukturering & matchning"}, meta: { en: "NER · entity resolution · LEI-link", sv: "NER · entity resolution · LEI-länk" } },
{ key: "enrich", title: { en: "Enrichment & fusion", sv: "Berikning & fusion" }, meta: { en: "multi-source agreement", sv: "multi-source agreement" } },
{ key: "quality", title: { en: "Quality control", sv: "Kvalitetskontroll" }, meta: { en: "expectations · dedup · threshold", sv: "expectations · dedup · tröskel" } },
];
const MARKET_KEYS = [
{ code: "SE", speed: 1.0 },
{ code: "NO", speed: 0.85 },
{ code: "DK", speed: 0.7 },
{ code: "FI", speed: 0.5 },
];
function prefersReduced() {
return typeof window !== "undefined" && window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
}
export default function ProductionPage() {
const t = useT();
const { id } = useParams<{ id: string }>();
const searchParams = useSearchParams();
const reveal = useReveal<HTMLDivElement>();
const [running, setRunning] = useState(false);
const [done, setDone] = useState(false);
const [progress, setProgress] = useState<number[]>([0, 0, 0, 0, 0]);
const [markets, setMarkets] = useState<number[]>([0, 0, 0, 0]);
const [conf, setConf] = useState(0);
const [feed, setFeed] = useState<{ t: string; msg: string; kind: "ok" | "run" }[]>([]);
const timer = useRef<ReturnType<typeof setInterval> | null>(null);
const tick = useRef(0);
const [order, setOrder] = useState<{ markets: string[]; volume: number } | null>(null);
useEffect(() => {
if (searchParams.get("deposit") === "success") {
toast.success(t({ en: "Deposit received. Production has started.", sv: "Förskott mottaget. Produktionen har startat." }));
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
useEffect(() => {
const fromLocal = () => {
const c = getLocalOrder(id)?.config as { markets?: string[]; volume?: number } | undefined;
if (c) setOrder({ markets: c.markets ?? [], volume: c.volume ?? 0 });
};
fetch(`/api/orders/${id}`)
.then((r) => (r.ok ? r.json() : null))
.then((o) => {
const c = o?.config as { markets?: string[]; volume?: number } | undefined;
if (c) setOrder({ markets: c.markets ?? [], volume: c.volume ?? 0 });
else fromLocal();
})
.catch(fromLocal);
}, [id]);
const finish = () => {
if (timer.current) {
clearInterval(timer.current);
timer.current = null;
}
setProgress([100, 100, 100, 100, 100]);
setMarkets([100, 100, 100, 100]);
setConf(94);
setDone(true);
setRunning(false);
setFeed((f) => [{ t: stamp(), msg: t({ en: "Delivered. 94% confidence. 4,980 records.", sv: "Levererad. 94 % konfidens. 4 980 poster." }), kind: "ok" }, ...f]);
};
const stamp = () => {
const s = 10 + Math.floor(tick.current / 2);
return `00:${String(s).padStart(2, "0")}`;
};
const start = () => {
if (running || done) return;
if (prefersReduced()) {
finish();
return;
}
setRunning(true);
setFeed([{ t: "00:00", msg: t({ en: `Order ${id}. Deposit received.`, sv: `Order ${id}. Depå mottagen.` }), kind: "run" }]);
timer.current = setInterval(() => {
tick.current += 1;
setProgress((prev) => {
const next = [...prev];
const i = next.findIndex((p) => p < 100);
if (i === -1) return prev;
next[i] = Math.min(100, next[i] + 8 + Math.random() * 10);
if (next[i] >= 100 && i < STAGES.length) {
setFeed((f) => [{ t: stamp(), msg: t({ en: `${STAGES[i].title.en}. Done.`, sv: `${STAGES[i].title.sv}. Klar.` }), kind: "ok" as const }, ...f].slice(0, 12));
}
return next;
});
setMarkets((prev) => prev.map((m, idx) => Math.min(100, m + (6 + Math.random() * 6) * MARKET_KEYS[idx].speed)));
setConf((c) => Math.min(94, c + 2.5 + Math.random() * 2));
}, 320);
};
useEffect(() => {
if (progress.every((p) => p >= 100) && running) finish();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [progress, running]);
useEffect(() => () => { if (timer.current) clearInterval(timer.current); }, []);
const overall = Math.round(progress.reduce((a, b) => a + b, 0) / STAGES.length);
const status = done ? t({ en: "Delivered", sv: "Levererad" }) : running ? `${overall} %` : t({ en: "Waiting", sv: "Väntar" });
return (
<main id="main-content" className="min-h-screen bg-background text-foreground">
<OrderStepper active={3} />
<div ref={reveal} className="mx-auto max-w-[80rem] px-6">
{/* masthead — oversized numeral as graphic texture */}
<header className="relative border-b border-border py-16 md:py-20">
<span
aria-hidden
className="pointer-events-none absolute -top-6 right-0 select-none font-mono text-[clamp(7rem,18vw,15rem)] font-medium leading-none tracking-[-0.04em] text-foreground/[0.04]"
>
03
</span>
<p className="reveal font-mono text-[11px] uppercase tracking-[0.18em] text-muted-foreground">
{t({ en: "Step 03 — Production", sv: "Steg 03 — Produktion" })}
</p>
<h1 className="reveal delay-1 mt-5 max-w-[18ch] text-[clamp(2.6rem,7vw,5.5rem)] font-medium leading-[0.95] tracking-[-0.035em]">
{t({ en: "Watch it happen.", sv: "Se det hända." })}
</h1>
<p className="reveal delay-2 mt-5 font-mono text-sm text-muted-foreground">
{order
? `${order.markets.join(" · ") || "—"} · ${new Intl.NumberFormat("sv-SE").format(order.volume)} ${t({ en: "records", sv: "poster" })}`
: t({ en: "Live. Source by source.", sv: "Live. Källa för källa." })}
</p>
</header>
{/* control row — single shared baseline */}
<div className="reveal delay-2 flex flex-wrap items-stretch gap-px border-b border-border bg-border">
<button
type="button"
onClick={start}
disabled={running || done}
className="group flex items-center gap-3 bg-background px-6 py-5 font-mono text-[12px] uppercase tracking-[0.12em] transition-colors hover:bg-foreground hover:text-background disabled:opacity-40 disabled:hover:bg-background disabled:hover:text-foreground"
>
<span className="text-[var(--accent-red)] transition-colors group-hover:text-background group-disabled:text-foreground">
{done ? "✓" : running ? "●" : "▸"}
</span>
{done ? t({ en: "Done", sv: "Klar" }) : running ? t({ en: "Running", sv: "Kör" }) : t({ en: "Start", sv: "Starta" })}
</button>
<span className="flex flex-1 items-center bg-background px-6 py-5 font-mono text-[11px] uppercase tracking-[0.1em] text-muted-foreground">
{t({ en: "Order", sv: "Order" })} {id}
</span>
<span className="flex items-center gap-3 bg-background px-6 py-5 font-mono text-[11px] uppercase tracking-[0.1em]">
<span className="text-muted-foreground">{t({ en: "Status", sv: "Status" })}</span>
<span className="tabular-nums text-foreground">{status}</span>
</span>
<span className="flex items-center gap-3 bg-background px-6 py-5 font-mono text-[11px] uppercase tracking-[0.1em]">
<span className="text-muted-foreground">{t({ en: "ETA", sv: "ETA" })}</span>
<span className="tabular-nums text-foreground">{t({ en: "≈ 4 days", sv: "≈ 4 dgr" })}</span>
</span>
</div>
<div className="grid grid-cols-1 lg:grid-cols-[1fr_340px]">
{/* stages — numbered ledger, hairline-separated */}
<div className="reveal-left delay-1 border-border lg:border-r">
{STAGES.map((s, i) => {
const p = Math.round(progress[i]);
const isDone = p >= 100;
const isRun = !isDone && (i === 0 || progress[i - 1] >= 100) && running;
const accent = isDone ? "var(--prov-3)" : isRun ? "var(--accent-red)" : "var(--muted-foreground)";
return (
<div
key={s.key}
className="group relative border-b border-border py-7 pl-6 pr-6 transition-colors hover:bg-secondary/40"
>
{/* state marker rail */}
<span
aria-hidden
className="absolute left-0 top-0 h-full w-px transition-all"
style={{ backgroundColor: isDone || isRun ? accent : "transparent" }}
/>
<div className="flex items-baseline justify-between gap-4">
<div className="flex items-baseline gap-4">
<span className="font-mono text-[11px] tabular-nums text-muted-foreground">
{String(i + 1).padStart(2, "0")}
</span>
<span className="text-base font-medium tracking-[-0.01em]">{t(s.title)}</span>
</div>
<span className="font-mono text-sm tabular-nums" style={{ color: accent }}>
{p}%
</span>
</div>
<div className="mt-4 h-px w-full bg-border">
<div
className="h-px transition-all duration-300"
style={{ width: `${p}%`, backgroundColor: isDone ? "var(--prov-3)" : "var(--foreground)" }}
/>
</div>
<p className="mt-3 pl-10 font-mono text-[10.5px] uppercase tracking-[0.08em] text-muted-foreground">
{t(s.meta)}
</p>
</div>
);
})}
</div>
{/* right column — gauge, markets, feed */}
<aside className="reveal-right delay-2 flex flex-col">
{/* confidence gauge */}
<div className="border-b border-border px-6 py-10 text-center">
<ConfidenceRing value={conf} unitLabel={t({ en: "PERCENT", sv: "PROCENT" })} />
<p className="mt-5 font-mono text-[10.5px] uppercase tracking-[0.14em] text-muted-foreground">
{t({ en: "Confidence — deliverable", sv: "Konfidens — levererbart" })}
</p>
</div>
{/* per market */}
<div className="border-b border-border px-6 py-7">
<p className="font-mono text-[10.5px] uppercase tracking-[0.14em] text-muted-foreground">{t({ en: "Per market", sv: "Per marknad" })}</p>
<div className="mt-5 flex flex-col gap-3.5">
{MARKET_KEYS.map((m, i) => (
<div key={m.code} className="flex items-center gap-3">
<span className="w-7 font-mono text-xs tabular-nums">{m.code}</span>
<div className="h-px flex-1 bg-border">
<div className="h-px bg-foreground transition-all duration-300" style={{ width: `${Math.round(markets[i])}%` }} />
</div>
<span className="w-10 text-right font-mono text-[10.5px] tabular-nums text-muted-foreground">
{Math.round(markets[i])}%
</span>
</div>
))}
</div>
</div>
{/* activity */}
<div className="px-6 py-7">
<p className="font-mono text-[10.5px] uppercase tracking-[0.14em] text-muted-foreground">{t({ en: "Activity", sv: "Aktivitet" })}</p>
<div className="mt-5 flex flex-col gap-2 font-mono text-[11px] leading-relaxed">
{feed.length === 0 ? <span className="text-muted-foreground">{t({ en: "Nothing yet.", sv: "Inget än." })}</span> : null}
{feed.map((f, i) => (
<div key={i} className="flex gap-3">
<span className="tabular-nums text-muted-foreground">{f.t}</span>
<span style={{ color: f.kind === "ok" ? "var(--prov-3)" : "var(--accent-red)" }}>{f.msg}</span>
</div>
))}
</div>
</div>
</aside>
</div>
{done ? (
<div className="border-t border-border py-12">
<Link
href={`/order/${id}/validera`}
className="group inline-flex items-center gap-3 bg-foreground px-7 py-4 font-mono text-[12px] uppercase tracking-[0.12em] text-background transition-colors hover:bg-[var(--accent-red)]"
>
{t({ en: "Review the result", sv: "Granska resultatet" })}
<span className="transition-transform duration-300 group-hover:translate-x-1">→</span>
</Link>
</div>
) : null}
</div>
</main>
);
}
function ConfidenceRing({ value, unitLabel }: { value: number; unitLabel: string }) {
const r = 52;
const c = 2 * Math.PI * r;
const off = c - (value / 100) * c;
return (
<svg viewBox="0 0 130 130" className="mx-auto h-40 w-40">
<circle cx="65" cy="65" r={r} fill="none" stroke="var(--secondary)" strokeWidth="6" />
<circle
cx="65" cy="65" r={r} fill="none" stroke="var(--prov-3)" strokeWidth="6"
strokeDasharray={c} strokeDashoffset={off} strokeLinecap="butt"
transform="rotate(-90 65 65)" style={{ transition: "stroke-dashoffset .3s" }}
/>
<text x="65" y="64" textAnchor="middle" className="fill-foreground font-mono" style={{ fontSize: 30, letterSpacing: "-0.02em" }}>
{Math.round(value)}
</text>
<text x="65" y="84" textAnchor="middle" className="fill-muted-foreground font-mono" style={{ fontSize: 10, letterSpacing: "0.14em" }}>
{unitLabel}
</text>
</svg>
);
}
+374
View File
@@ -0,0 +1,374 @@
"use client";
import { useParams } from "next/navigation";
import { useState } from "react";
import { toast } from "sonner";
import { OrderStepper } from "@/components/order-stepper";
import { useT } from "@/components/locale-provider";
import { useReveal } from "@/hooks/use-reveal";
import { CellProvenance, ProvenanceBadge, PROVENANCE_LEGEND } from "@/components/provenance-badge";
import { MARKETS, SAMPLE_ROWS, formatSEK } from "@/lib/data";
import type { Loc } from "@/lib/data";
type TabKey = "table" | "coverage" | "schema" | "quality";
const TABS: { key: TabKey; label: Loc }[] = [
{ key: "table", label: { en: "Table", sv: "Tabell" } },
{ key: "coverage", label: { en: "Coverage", sv: "Täckning" } },
{ key: "schema", label: { en: "Schema & arch", sv: "Schema & arkitektur"} },
{ key: "quality", label: { en: "Quality report", sv: "Kvalitetsrapport" } },
];
const DESTINATIONS: { id: string; label: Loc }[] = [
{ id: "csv", label: { en: "CSV", sv: "CSV" } },
{ id: "nocodb", label: { en: "Table view (NocoDB)", sv: "Tabellvy (NocoDB)" } },
{ id: "parquet", label: { en: "Parquet", sv: "Parquet" } },
{ id: "json", label: { en: "JSON", sv: "JSON" } },
{ id: "metabase", label: { en: "Dashboard (Metabase)", sv: "Dashboard (Metabase)" } },
{ id: "api", label: { en: "API", sv: "API" } },
{ id: "webhook", label: { en: "Webhook", sv: "Webhook" } },
{ id: "fivecrm", label: { en: "FiveCRM", sv: "FiveCRM" } },
{ id: "sheets", label: { en: "Google Sheets", sv: "Google Sheets" } },
];
const DIMENSIONS: { label: Loc; value: number; amber: boolean }[] = [
{ label: { en: "Complete", sv: "Komplett" }, value: 97, amber: false },
{ label: { en: "Freshness", sv: "Färskhet" }, value: 93, amber: false },
{ label: { en: "Corroboration", sv: "Korroborering" }, value: 88, amber: true },
{ label: { en: "Uniqueness", sv: "Unikhet" }, value: 99, amber: false },
{ label: { en: "Validity", sv: "Giltighet" }, value: 96, amber: false },
];
const CHECKS: Loc[] = [
{ en: "Org.no against register checksum", sv: "Org.nr mot register-checksumma" },
{ en: "LEI against GLEIF", sv: "LEI mot GLEIF" },
{ en: "Email MX-verified", sv: "E-post MX-verifierad" },
{ en: "Duplicates merged", sv: "Dubbletter sammanslagna" },
{ en: "20 records below threshold omitted", sv: "20 poster under tröskel utelämnade" },
{ en: "Sanctions/PEP screen — no match", sv: "Sanktions/PEP-skärm utan träff" },
];
const TABLE_HEADERS: Loc[] = [
{ en: "Org.no", sv: "Org.nr" },
{ en: "Company", sv: "Bolag" },
{ en: "HQ", sv: "Säte" },
{ en: "SNI", sv: "SNI" },
{ en: "Employees", sv: "Anställda" },
{ en: "Revenue (tSEK)", sv: "Oms. (tkr)" },
{ en: "Email", sv: "E-post" },
{ en: "LEI", sv: "LEI" },
];
const ENTITIES = [
{ name: "dim_company", key: true, cols: ["company_id PK", "org_nr", "lei FK", "name"] },
{ name: "fact_financials", key: false, cols: ["company_id FK", "year", "revenue", "result"] },
{ name: "dim_contact", key: false, cols: ["contact_id PK", "company_id FK", "email"] },
{ name: "dim_ubo", key: false, cols: ["ubo_id PK", "company_id FK", "share_pct"] },
{ name: "bridge_provenance", key: true, cols: ["field_id PK", "source_id FK", "confidence", "fetched_at"] },
{ name: "dim_source", key: false, cols: ["source_id PK", "name", "license", "freshness"] },
];
export default function ValidationPage() {
const t = useT();
const { id } = useParams<{ id: string }>();
const [tab, setTab] = useState<TabKey>("table");
const [dests, setDests] = useState<string[]>(["csv", "nocodb"]);
const [approved, setApproved] = useState(false);
const ref = useReveal<HTMLElement>();
const toggleDest = (d: string) => setDests((p) => (p.includes(d) ? p.filter((x) => x !== d) : [...p, d]));
function handleTabKey(e: React.KeyboardEvent, idx: number) {
let next = -1;
if (e.key === "ArrowRight") next = (idx + 1) % TABS.length;
else if (e.key === "ArrowLeft") next = (idx - 1 + TABS.length) % TABS.length;
else if (e.key === "Home") next = 0;
else if (e.key === "End") next = TABS.length - 1;
if (next !== -1) {
e.preventDefault();
setTab(TABS[next].key);
document.getElementById(`validera-tab-${TABS[next].key}`)?.focus();
}
}
async function approve() {
try {
const r = await fetch(`/api/orders/${id}`, {
method: "PATCH",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ status: "accepted" }),
});
if (!r.ok) throw new Error("api");
setApproved(true);
toast.success(t({ en: "Order approved. Escrow released.", sv: "Order godkänd. Escrow frigiven." }));
} catch {
toast.error(t({ en: "Could not approve. Try again.", sv: "Kunde inte godkänna. Försök igen." }));
}
}
return (
<main ref={ref} id="main-content" className="min-h-screen bg-background text-foreground">
<OrderStepper active={4} />
{/* header */}
<div className="relative overflow-hidden border-b border-border">
<span aria-hidden className="pointer-events-none absolute -right-3 -top-6 select-none font-mono text-[clamp(7rem,22vw,15rem)] font-medium leading-none tracking-[-0.05em] text-secondary">
04
</span>
<div className="relative mx-auto max-w-[80rem] px-6 py-16 md:py-24">
<div className="reveal flex items-center gap-3">
<span aria-hidden className="animate-float inline-block h-2 w-2" style={{ backgroundColor: "var(--accent-red)" }} />
<p className="font-mono text-[11px] uppercase tracking-[0.16em] text-muted-foreground">
{t({ en: "Step 04 — Validate", sv: "Steg 04 — Validera" })}
</p>
</div>
<h1 className="reveal delay-1 mt-6 max-w-3xl text-[clamp(2.4rem,6vw,4.5rem)] font-medium leading-[0.95] tracking-[-0.035em]">
{t({ en: "Review everything.", sv: "Granska allt." })}
<br />
{t({ en: "Approve freely.", sv: "Godkänn fritt." })}
</h1>
<p className="reveal delay-2 mt-6 font-mono text-[11px] uppercase tracking-[0.1em] text-muted-foreground">
{t({ en: "The source is visible. Always. Nothing guessed.", sv: "Källan syns. Alltid. Inget gissat." })}
</p>
</div>
</div>
<div className="mx-auto max-w-[80rem] px-6 py-12">
{/* tabs */}
<div role="tablist" aria-label={t({ en: "Result views", sv: "Resultatvyer" })} className="reveal flex flex-wrap border-b border-border">
{TABS.map((tb, i) => (
<button
key={tb.key}
id={`validera-tab-${tb.key}`}
role="tab"
aria-selected={tab === tb.key}
aria-controls={`validera-panel-${tb.key}`}
onClick={() => setTab(tb.key)}
onKeyDown={(e) => handleTabKey(e, i)}
className="group relative -mb-px px-5 py-3.5 font-mono text-[11px] uppercase tracking-[0.12em] transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background"
style={{ color: tab === tb.key ? "var(--foreground)" : "var(--muted-foreground)" }}
>
<span className="mr-2 text-muted-foreground">{String(i + 1).padStart(2, "0")}</span>
{t(tb.label)}
<span
aria-hidden
className="absolute bottom-0 left-0 h-px bg-foreground transition-all duration-300 ease-out"
style={{ width: tab === tb.key ? "100%" : "0%" }}
/>
</button>
))}
</div>
<div
className="mt-10"
role="tabpanel"
id={`validera-panel-${tab}`}
aria-labelledby={`validera-tab-${tab}`}
tabIndex={0}
>
{/* Table tab */}
{tab === "table" ? (
<div className="reveal-fade">
<div className="mb-5 flex flex-wrap gap-2">
{PROVENANCE_LEGEND.map((l) => (
<ProvenanceBadge key={l.level} level={l.level} source={t(l.text)} />
))}
</div>
<div className="overflow-x-auto border border-border">
<table className="w-full border-collapse text-sm">
<thead>
<tr className="border-b border-border bg-secondary">
{TABLE_HEADERS.map((h) => (
<th key={h.en} className="px-3 py-2.5 text-left font-mono text-[10px] uppercase tracking-[0.1em] text-muted-foreground">{t(h)}</th>
))}
</tr>
</thead>
<tbody>
{SAMPLE_ROWS.map((r) => (
<tr key={r.orgnr} className="border-b border-border transition-colors last:border-b-0 hover:bg-secondary/60">
<td className="px-3 py-2.5 font-mono text-xs">{r.orgnr}<CellProvenance level={3} /></td>
<td className="px-3 py-2.5">{r.bolag}<CellProvenance level={3} /></td>
<td className="px-3 py-2.5">{r.sate}<CellProvenance level={3} /></td>
<td className="px-3 py-2.5 font-mono text-xs">{r.sni}<CellProvenance level={2} /></td>
<td className="px-3 py-2.5 font-mono text-xs">{new Intl.NumberFormat("sv-SE").format(r.anstallda)}<CellProvenance level={2} /></td>
<td className="px-3 py-2.5 font-mono text-xs">{new Intl.NumberFormat("sv-SE").format(r.oms)}<CellProvenance level={2} /></td>
<td className="px-3 py-2.5 text-xs">
{r.epost ? (
<>{r.epost}<CellProvenance level={r.epostLevel} /></>
) : (
<span className="text-muted-foreground">— {t({ en: "licence (FI)", sv: "licens (FI)" })}<CellProvenance level={0} /></span>
)}
</td>
<td className="px-3 py-2.5 font-mono text-xs">{r.lei}<CellProvenance level={3} /></td>
</tr>
))}
</tbody>
</table>
</div>
<p className="mt-4 font-mono text-[10.5px] uppercase tracking-[0.08em] text-muted-foreground">
{t({ en: "Every cell carries its source. Empty = licence, never guessed.", sv: "Varje cell bär sin källa. Tom = licens, aldrig gissning." })}
</p>
</div>
) : null}
{/* Coverage tab */}
{tab === "coverage" ? (
<div className="reveal-fade">
<p className="mb-4 font-mono text-[10.5px] uppercase tracking-[0.12em] text-muted-foreground">
{t({ en: "Per market", sv: "Per marknad" })}
</p>
<div className="grid grid-cols-[repeat(auto-fill,minmax(96px,1fr))] gap-px bg-border">
{MARKETS.filter((m) => m.live).map((m) => (
<div key={m.code} className="group bg-background p-3 transition-colors hover:bg-secondary/40">
<p className="font-mono text-sm font-semibold tracking-[-0.01em]">{m.code}</p>
<p className="font-mono text-[10.5px] text-muted-foreground">{m.coverage}%</p>
<div className="mt-2 h-1 w-full bg-secondary">
<div className="h-full" style={{ width: `${m.coverage}%`, backgroundColor: m.coverage >= 95 ? "var(--prov-3)" : "var(--prov-2)" }} />
</div>
</div>
))}
</div>
<div className="mt-px grid grid-cols-1 gap-px bg-border sm:grid-cols-3">
{([
["4 980", { en: "records delivered", sv: "poster levererade" }],
["20", { en: "omitted — not guessed", sv: "utelämnade — ej gissade" }],
["3.2", { en: "sources per field", sv: "källor per fält" }],
] as [string, Loc][]).map(([n, l]) => (
<div key={l.en} className="bg-background p-6">
<p className="text-4xl font-medium tracking-[-0.03em]">{n}</p>
<p className="mt-2 font-mono text-[10.5px] uppercase tracking-[0.1em] text-muted-foreground">{t(l)}</p>
</div>
))}
</div>
</div>
) : null}
{/* Schema tab */}
{tab === "schema" ? (
<div
className="reveal-fade border border-border p-6 md:p-8"
style={{ backgroundImage: "radial-gradient(var(--border) 1px, transparent 1px)", backgroundSize: "16px 16px" }}
>
<p className="mb-6 font-mono text-[10.5px] uppercase tracking-[0.12em] text-muted-foreground">
{t({ en: "Star schema · traceable per field", sv: "Stjärnschema · spårbart per fält" })}
</p>
<div className="grid grid-cols-2 gap-4 md:grid-cols-3">
{ENTITIES.map((e) => (
<div key={e.name} className="group bg-background transition-[border-color]" style={{ border: e.key ? "1px solid var(--accent-red)" : "1px solid var(--border)" }}>
<div className="border-b border-border px-3 py-2 font-mono text-[11px] tracking-[0.02em]">{e.name}</div>
<ul className="px-3 py-2 font-mono text-[10.5px] leading-relaxed text-muted-foreground">
{e.cols.map((c) => (<li key={c}>{c}</li>))}
</ul>
</div>
))}
</div>
<p className="mt-6 border-t border-border pt-4 font-mono text-[10.5px] uppercase tracking-[0.08em] text-muted-foreground">
{t({ en: "Every field → bridge_provenance. No value without a source.", sv: "Varje fält → bridge_provenance. Ingen uppgift utan källa." })}
</p>
</div>
) : null}
{/* Quality tab */}
{tab === "quality" ? (
<div className="reveal-fade grid grid-cols-1 gap-px bg-border md:grid-cols-2">
<div className="bg-background p-6">
<p className="font-mono text-[10.5px] uppercase tracking-[0.12em] text-muted-foreground">
{t({ en: "Per dimension", sv: "Per dimension" })}
</p>
<div className="mt-5 flex flex-col gap-4">
{DIMENSIONS.map((d) => (
<div key={d.label.en}>
<div className="flex justify-between font-mono text-xs">
<span>{t(d.label)}</span>
<span className="text-muted-foreground">{d.value}%</span>
</div>
<div className="mt-1.5 h-1.5 w-full bg-secondary">
<div className="h-full" style={{ width: `${d.value}%`, backgroundColor: d.amber ? "var(--prov-2)" : "var(--prov-3)" }} />
</div>
</div>
))}
</div>
</div>
<div className="bg-background p-6">
<p className="font-mono text-[10.5px] uppercase tracking-[0.12em] text-muted-foreground">
{t({ en: "Passed checks", sv: "Passerade kontroller" })}
</p>
<ul className="mt-5 flex flex-col gap-2.5 text-sm">
{CHECKS.map((c) => (
<li key={c.en} className="flex items-start gap-2.5">
<span aria-hidden className="mt-1.5 inline-block h-[9px] w-[9px] flex-shrink-0" style={{ backgroundColor: "var(--prov-3)" }} />
<span>{t(c)}</span>
</li>
))}
</ul>
</div>
</div>
) : null}
</div>
{/* destinations */}
<div className="reveal mt-14 border-t border-border pt-8">
<p className="font-mono text-[10.5px] uppercase tracking-[0.12em] text-muted-foreground">
{t({ en: "Deliver to", sv: "Leverera till" })}
</p>
<div role="group" aria-label={t({ en: "Delivery destinations", sv: "Leveransdestinationer" })} className="mt-4 flex flex-wrap gap-2">
{DESTINATIONS.map((d) => {
const on = dests.includes(d.id);
return (
<button
key={d.id}
aria-pressed={on}
onClick={() => toggleDest(d.id)}
className="border px-3.5 py-2 font-mono text-[11px] uppercase tracking-[0.08em] transition-colors hover:border-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background"
style={{
borderColor: on ? "var(--foreground)" : "var(--border)",
backgroundColor: on ? "var(--foreground)" : "transparent",
color: on ? "var(--background)" : "var(--foreground)",
}}
>
{t(d.label)}
</button>
);
})}
</div>
</div>
{/* action bar */}
<div className="reveal mt-8 border border-border p-6 md:p-8">
{approved ? (
<div className="border p-5" style={{ borderColor: "var(--prov-3)" }}>
<p className="flex items-center gap-2.5 font-mono text-sm" style={{ color: "var(--prov-3)" }}>
<span aria-hidden className="inline-block h-[9px] w-[9px]" style={{ backgroundColor: "var(--prov-3)" }} />
{t({ en: "Approved. Final payment released. Export unlocked.", sv: "Godkänd. Slutbetalning frigjord. Export upplåst." })}
</p>
<p className="mt-2 font-mono text-[11px] tracking-[0.02em] text-muted-foreground">
{t({ en: "Order", sv: "Order" })} {id} · {dests.map((id) => t(DESTINATIONS.find((d) => d.id === id)?.label ?? { en: id, sv: id })).join(" · ") || "—"}.
</p>
</div>
) : (
<div className="flex flex-col gap-6 md:flex-row md:items-center md:justify-between">
<div>
<p className="text-lg font-medium tracking-[-0.02em]">
{t({ en: "Happy? Release the half.", sv: "Nöjd? Frigör hälften." })}
</p>
<p className="mt-1.5 max-w-md font-mono text-[11px] uppercase leading-relaxed tracking-[0.06em] text-muted-foreground">
{t({ en: "Approve → escrow releases the rest. Full export. Otherwise: revision, at no cost.", sv: "Godkänn → depån släpper resten. Full export. Annars: revidering, utan kostnad." })}
</p>
</div>
<div className="flex flex-shrink-0 gap-3">
<button className="border border-foreground px-5 py-3 font-mono text-[12px] uppercase tracking-[0.1em] transition-colors hover:bg-foreground hover:text-background">
{t({ en: "Revise", sv: "Revidera" })}
</button>
<button
onClick={approve}
className="bg-foreground px-5 py-3 font-mono text-[12px] uppercase tracking-[0.1em] text-background transition-colors hover:bg-[var(--accent-red)]"
>
{t({ en: "Approve · release 50%", sv: "Godkänn · frigör 50 %" })}
</button>
</div>
</div>
)}
</div>
</div>
</main>
);
}