import { forwardRef } from 'react' import type { ArchChapter, ArchStep } from '@/lib/types' import { cn } from '@/lib/utils' import { Diagram } from './Diagrams' /** One chapter (one level of detail): its steps on the left, read top to bottom, and its * diagram pinned on the right (on a phone, above the steps). The active step (the one * being read, or the one clicked) lights up the boxes it talks about. */ export function Chapter({ chapter, number, active, onStep, stepRef, }: { chapter: ArchChapter number: number active: number // the step being read in this chapter, -1 for none onStep: (i: number) => void stepRef: (i: number, el: HTMLElement | null) => void }) { const lit = active >= 0 ? chapter.steps[active].highlight : null return (

Step {number}

{chapter.title}

{chapter.lead}

{chapter.steps.map((s, i) => ( stepRef(i, el)} step={s} active={i === active} onClick={() => onStep(i)} /> ))}
{chapter.title} {chapter.diagram.kind === 'grid' ? 'Lit row: the step you are reading · — : no such step' : 'Lit boxes: the step you are reading'}
) } const Step = forwardRef void }>(function Step( { step, active, onClick }, ref, ) { const d = step.details const hasDetails = d.numbers.length > 0 || d.example || d.tried.length > 0 || d.files.length > 0 return (
(e.key === 'Enter' || e.key === ' ') && (e.preventDefault(), onClick())} aria-pressed={active} className={cn( 'cursor-pointer rounded-xl border-l-4 py-1 pl-4 transition-colors outline-none focus-visible:ring-2 focus-visible:ring-primary', active ? 'border-primary' : 'border-transparent hover:border-border', )} >

{step.point}

{step.body}

{hasDetails && (
Details: numbers, a real example, what we tried
{d.numbers.length > 0 && (
{d.numbers.map((x) => (
{x.label}
{x.value}
))}
)} {d.example && (

Real example · {d.example.title}

{d.example.body}
)} {d.tried.length > 0 && (

Tried or considered, and rejected

    {d.tried.map((t) => (
  • {t}
  • ))}
)} {d.files.length > 0 && (
{d.files.map((f) => ( {f} ))}
)}
)}
) })