import type { Writable } from 'node:stream' import { styleText } from 'node:util' import type { ActiveStep } from './stepper.ts' /** * Render the breadcrumb header into the card region. * * Completed steps show their label and answer in green. * The current step is highlighted in cyan. * Future steps are dimmed. */ export function renderHeader( output: Writable, steps: ActiveStep[], currentIndex: number, answers: Record, ): void { const separator = styleText('dim', ' > ') const crumbs = steps.map((step, i) => { if (i < currentIndex) { const value = formatValue(answers[step.key]) return styleText('green', `${step.label}: ${value}`) } if (i === currentIndex) { return styleText('cyan', step.label) } return styleText('dim', step.label) }) const stepCount = styleText( 'dim', `Step ${currentIndex + 1} of ${steps.length}`, ) const breadcrumb = crumbs.join(separator) output.write(`${stepCount}\n${breadcrumb}\n\n`) } function formatValue(value: unknown): string { if (value === undefined || value === null) return '' if (typeof value === 'boolean') return value ? 'yes' : 'no' const str = String(value) return str.length > 20 ? `${str.slice(0, 20)}...` : str }