import { CircleAlert, CircleCheck, ExternalLink } from 'lucide-react' import { useState } from 'react' import { VERDICTS } from '@/lib/content' import { inForce } from '@/lib/format' import { pieces } from '@/lib/highlight' import type { CitationView } from '@/lib/types' import { cn } from '@/lib/utils' const TONE = { good: 'text-emerald-600', warn: 'text-amber-600', bad: 'text-red-600', } /** The answer's numbered sources as a row of chips; clicking one opens it below the * answer: where it is (version, pages, link), the checker's verdict, the quote, and the * section text with the quote highlighted. The colour comes from the VERDICT, never * from how the quote was located (9a audit). */ export function Sources({ citations }: { citations: CitationView[] }) { const [open, setOpen] = useState(null) const shown = citations.find((c) => c.n === open) return (
Sources {citations.map((c) => { const v = VERDICTS[c.verdict] const Icon = v.tone === 'good' ? CircleCheck : CircleAlert return ( ) })}
{shown && }
) } /** A short name for a source: the form and its section number. */ function label(c: CitationView): string { const s = c.section const section = c.source_id.includes('#') ? ` §${c.source_id.split('#')[1]}` : '' return `${s?.form_id ?? c.source_id.split('#')[0]}${section}` } function SourceDetail({ c }: { c: CitationView }) { const v = VERDICTS[c.verdict] const s = c.section const x = c.excerpt const highlighted = x?.parts.some((p) => p.spans.length > 0) return (
{s?.title ?? c.source_id} {c.source_id} {s ? ` · ${inForce(s.effective_from, s.effective_to)}` : ''} {s?.pages ? ` · ${s.pages}` : ''} {s?.url && ( source )}

{v.label}: {v.why} {c.verdict !== 'exact' && c.problems.length > 0 ? ` (${c.problems.join('; ')})` : ''}

{x && (
{s?.heading_path &&

{s.heading_path}

} {!highlighted && (

The quote could not be placed in this text; the start of the section is shown.

)} {x.cut_start && } {x.parts.map((part, i) => ( {i > 0 && } {pieces(part.text, part.spans).map((p, j) => p.mark ? ( {p.text} ) : ( {p.text} ), )} ))} {x.cut_end && }
)} {!x &&
“{c.quote}”
}
) } function Gap() { return […] }