import Link from 'next/link';
import { Section, Note } from '@/components/ui/section';
import { EmptyState } from '@/components/ui/empty-state';
import { ClaimBadge, ConfidenceBadge } from '@/components/ui/badge';
import { JsonView } from '@/components/ui/json-view';
import { rankingsForCancer } from '@/lib/queries/rankings';
import { fmtDate, fmtInt, fmtValue, scopeLabel, unitLabel } from '@/lib/format';
import { latestYearPerScope } from '@/lib/rankings-util';
import { CancerGapCard } from '@/components/research-gap/cancer-gap-card';
import type { CancerBundle } from '../load';
function Delta({ rank, prev }: { rank: number; prev: number | null }) {
if (prev == null) return new;
const d = prev - rank;
if (d === 0) return =;
return (
0 ? 'text-ok' : 'text-danger'} title={`Previous rank ${prev}`}>
{d > 0 ? '▲' : '▼'} {Math.abs(d)}
);
}
export async function RankingsTab({ b }: { b: CancerBundle }) {
const allRows = await rankingsForCancer(b.cancer.id);
// One row per (metric, geography, sex, age, level): the latest year only. Historical years stay on the ranking pages.
const { rows, hidden: hiddenYears } = latestYearPerScope(allRows);
if (rows.length === 0) {
return (
| Metric | Scope | Rank / eligible | Δ | Value | Percentile | Confidence | Formula | Generated | Inputs |
|---|---|---|---|---|---|---|---|---|---|
| {r.metric_name} | {scopeLabel(r.scope_key)} | #{r.rank} / {fmtInt(r.eligible_entities)} |
|
{fmtValue(r.value, r.unit)} {unitLabel(r.unit)} | {r.percentile} |
|
{r.formula_version} | {fmtDate(r.generated_at)} |
showformula: {r.formula} inputs hash {r.inputs_hash} Trace lineage (admin) |