"use client"
import { parseEvidence, type EvidenceBlock } from "../lib/evidence-format"
/**
* Renders a finding's evidence as tables and labelled values.
*
* The evidence exists so a reader can verify the conclusion for
* themselves. A JSON dump technically contains the same facts but asks
* the reader to parse it first, which is the part they came here to
* avoid.
*/
export function AuditEvidence({ evidence, locale }: {
evidence: string | null
locale: string
}) {
const blocks = parseEvidence(evidence, locale)
if (blocks.length === 0) return null
return (
{blocks.map((block, i) => )}
)
}
function Block({ block }: { block: EvidenceBlock }) {
const title = block.title
? {block.title}
: null
if (block.kind === "table") {
return (
{title}
{/* Wide evidence scrolls inside its own box so the page itself
never scrolls sideways. */}
{/* Evidence is the widest thing on the page; on a narrow screen
it stacks like the rest rather than scrolling sideways. */}
{block.rows.map((row, i) => (
{row.map((cell, j) => cell === "—" || cell === "" ? null : (
{block.columns[j]}
{cell}
))}
))}
{block.columns.map((c) => (
|
{c}
|
))}
{block.rows.map((row, i) => (
{row.map((cell, j) => (
|
{cell}
|
))}
))}
)
}
if (block.kind === "pairs") {
return (
{title}
{block.entries.map(([label, value]) => (
- {label}
- {value}
))}
)
}
return (
{title}
{block.lines.length > 0 && (
{block.lines.map((line, i) => (
- {line}
))}
)}
)
}