import { useParams, Link, useNavigate } from 'react-router-dom' import { useQuery } from '@tanstack/react-query' import { fetchPolicyQuestion, type CanonicalArgument, type PolicyQuestionDetail, } from '../api/policyQuestions' import { expandStateName, titleCaseCity } from '../utils/formatters' const OUTCOME_COLORS: Record = { approved: 'bg-green-500', denied: 'bg-red-500', deferred: 'bg-amber-500', other: 'bg-gray-400', } function RollupBar({ q }: { q: PolicyQuestionDetail }) { const r = q.rollup const total = r.approved_count + r.denied_count + r.deferred_count + r.other_count const seg = (n: number) => (total > 0 ? `${(n / total) * 100}%` : '0%') const pct = r.jurisdictions_total > 0 ? Math.round((r.jurisdictions_approved / r.jurisdictions_total) * 100) : 0 return (
{r.instances_total === 0 ? (

No mapped instances yet.

) : ( <>

{r.jurisdictions_approved} of {r.jurisdictions_total} jurisdictions approved ({pct}%)

{r.decisions_total} local decision{r.decisions_total === 1 ? '' : 's'} {r.bills_total > 0 ? ` · ${r.bills_total} state bills` : ''} ·{' '} {r.states_total} state{r.states_total === 1 ? '' : 's'}

{(['approved', 'denied', 'deferred', 'other'] as const).map((k) => { const n = r[`${k}_count` as keyof typeof r] as number return n > 0 ? (
) : null })}
● approved {r.approved_count} ● denied {r.denied_count} ● deferred {r.deferred_count} ● other {r.other_count}
)}
) } function ArgumentCard({ a }: { a: CanonicalArgument }) { return (
{a.label} ×{a.member_count}
{a.summary &&

{a.summary}

}
{a.frame_label && ( {a.frame_label} )} {a.source_role && ( {a.source_role} )}
) } // "← Back" affordance: returns to the previous page in history (e.g. the home // "Big questions" section or search), falling back to the questions list when // the page was opened directly (no in-app history). function BackLink() { const navigate = useNavigate() return ( ) } export default function PolicyQuestionPage() { const { questionId } = useParams<{ questionId: string }>() const { data: q, isLoading, error } = useQuery({ queryKey: ['policy-question', questionId], queryFn: () => fetchPolicyQuestion(questionId as string), enabled: !!questionId, }) if (isLoading) { return (
) } if (error || !q) { return (

Unable to load this policy question.

Back to policy questions
) } const pros = q.arguments.filter((a) => a.stance === 'pro') const cons = q.arguments.filter((a) => a.stance === 'con') const other = q.arguments.filter((a) => a.stance !== 'pro' && a.stance !== 'con') return (

This question keeps coming up

{q.canonical_text}

{q.primary_theme && q.primary_theme !== '__unthemed__' && ( {q.primary_theme} )} {q.scope && scope: {q.scope}} {q.topic_code && ( CAP {q.topic_code} )}
{q.relations && q.relations.length > 0 && (

Across levels of government

    {q.relations.map((r) => (
  • {r.relation_type === 'preempts' ? r.direction === 'incoming' ? 'may be preempted by' : 'may preempt' : r.relation_type === 'implements' ? r.direction === 'incoming' ? 'may be enabled by' : 'may enable' : 'related to'} {r.canonical_text} {r.scope && ({r.scope})}
  • ))}
)}

Arguments for ({pros.length})

{pros.length ? pros.map((a) => ) : (

None extracted.

)}

Arguments against ({cons.length})

{cons.length ? cons.map((a) => ) : (

None extracted.

)}
{other.length > 0 && (

Other arguments

{other.map((a) => )}
)}

Where it came up ({q.rollup.instances_total})

{q.sample_instances.map((i) => ( ))}
{i.source_type === 'state_bill' ? ( {i.jurisdiction_name || expandStateName(i.state_code)} (bill) ) : ( {i.jurisdiction_name || titleCaseCity(i.city) || expandStateName(i.state_code)} )} {i.outcome_raw} {i.outcome_normalized}
) }