import Link from 'next/link'; import { Badge, ClaimBadge, StatusBadge } from '@/components/ui/badge'; import { SourceBadge, TableProvenance } from '@/components/ui/source-badge'; import type { ApprovalRow } from '@/lib/queries/drugs'; import type { ProvRow } from '@/lib/queries/provenance'; import { toInfo } from '@/lib/queries/provenance'; import { fmtDate, fmtInt } from '@/lib/format'; import { Pager } from '@/components/ui/pager'; import { pageInfo } from '@/lib/pagination'; /** * Jurisdiction-aware regulatory status (§13). Never a bare "approved". Approvals may come from * different authorities' datasets, so rows keep a compact badge with a dataset · version title; * the caption carries one full popover (first row's provenance) and the claim label. */ export function ApprovalsTable({ rows: allRows, prov, showDrug = true, showCancer = true, page = 1, pageSize = 50, hrefFor }: { rows: ApprovalRow[]; prov: Map; showDrug?: boolean; showCancer?: boolean; page?: number; pageSize?: number; hrefFor?: (page: number) => string }) { // Optional server-side pagination (URL state); without hrefFor the first page only is shown with a count. const info = pageInfo(page, pageSize, allRows.length); const rows = allRows.slice(info.offset, info.offset + pageSize); const first = rows[0]; const caption = first ? (toInfo(prov.get(first.provenance_id)) ?? { sourceSlug: first.source_slug, sourceName: first.source_name }) : null; const sources = new Set(rows.map((r) => r.source_slug)); return (
{caption ? ( }> {fmtInt(rows.length)} approval record{rows.length === 1 ? '' : 's'} {sources.size > 1 ? ` from ${sources.size} sources (hover a row badge for its dataset)` : ''} · authority, jurisdiction and indication text as published. ) : null}
{showDrug ? : null} {showCancer ? : null} {rows.map((a) => ( {showDrug ? ( ) : null} {showCancer ? ( ) : null} ))}
DrugJurisdiction · authorityCancerIndication Status Approval date Source
{a.drug_name} {a.jurisdiction} {a.authority} {a.tumor_agnostic ? Tumor-agnostic : null} {a.cancer_slug ? ( {a.cancer_name} ) : !a.tumor_agnostic ? ( — ) : null} {a.indication} {a.line_of_therapy ? {a.line_of_therapy} : null} {a.disease_stage ? {a.disease_stage} : null} {a.accelerated ? accelerated : null} {a.conditional ? conditional : null} {a.biomarker_ids.length ? biomarker-restricted : null} {a.source_status && a.source_status.toLowerCase() !== a.status ? ( source: {a.source_status} ) : null} {a.withdrawal_date ? since {fmtDate(a.withdrawal_date)} : null} {fmtDate(a.approval_date)}
{hrefFor ? : allRows.length > rows.length ?

Showing {rows.length} of {fmtInt(allRows.length)} approval records.

: null}
); }