import React from 'react'; import { cn } from '../lib/utils'; import { questionProgress, type QuestionPanelRow } from '../utils/questionAnswers'; /** * The annotations panel's Questions section (the approved Card mock): a * header with the progress count, a thin progress bar, and one row per * `:::question` block with its answer or "Not answered yet" and an * Open / answered state. A row whose question is no longer in the document * carries the Unanchored chip; its answer still exports. */ const CheckIcon = () => ( ); const StateTag: React.FC<{ row: QuestionPanelRow }> = ({ row }) => { if (row.orphaned) { return ( Unanchored ); } if (row.status === 'answered' || row.status === 'settled') { return ( {row.status === 'settled' ? 'Settled' : 'Answered'} ); } if (row.status === 'skipped') { return Skipped; } return ( Open ); }; export interface QuestionsPanelSectionProps { rows: readonly QuestionPanelRow[]; onSelect?: (row: QuestionPanelRow) => void; /** Remove an orphaned answer (its card is gone, so the panel is the only * place to drop it). Absent: no remove control. */ onRemoveOrphan?: (row: QuestionPanelRow) => void; } export const QuestionsPanelSection: React.FC = ({ rows, onSelect, onRemoveOrphan }) => { const { done, total } = questionProgress(rows); const complete = total > 0 && done === total; return (
Questions {total > 0 && {done}/{total}}
{total > 0 && ( )}
{rows.map((row) => { const ok = !row.orphaned && (row.status === 'answered' || row.status === 'settled'); const summary = row.answerText ?? 'Not answered yet'; const clickable = !!onSelect && !row.orphaned; const body = ( <> {row.number ? `Q${row.number}` : 'Q'} {row.prompt} {summary} {row.hasNote ? ' ยท has note' : ''} ); const rowClass = 'grid w-full grid-cols-[auto_1fr_auto] items-start gap-x-2 gap-y-0.5 rounded-[7px] px-2 py-2 text-left'; return clickable ? ( ) : (
{body} {row.orphaned && onRemoveOrphan && ( )}
); })}
); };