'use client' import { useEffect, useId, useMemo, useRef, type ReactNode } from 'react' import { CampaignListResults } from '@/components/campaign/shared/CampaignListPending' import { toCampaignWizardChromeState, useSetCampaignWizardChrome, type CampaignWizardChromeSkip, } from '@/components/campaign/shell/CampaignWizardChromeContext' import { CAMPAIGN_HOME } from '@/lib/campaignPaths' import { WIZARD_STEP_PENDING_MESSAGE, wizardFlowChromeAriaLabel } from '@/lib/campaignWizardCopy' import { cn } from '@/lib/utils' export type CampaignWizardShellProps = { flowTitle: string stepTitle?: string | null isEntryStep: boolean previousHref: string dismissHref?: string municipalityLabel?: string skip?: CampaignWizardChromeSkip trailingAction?: ReactNode contentAlign?: 'start' | 'end' /** When `'none'`, the shell does not move focus to the step title — use on form steps that autofocus an input. */ contentFocus?: 'title' | 'none' children: ReactNode } export const CampaignWizardShell = ({ flowTitle, stepTitle, isEntryStep, previousHref, dismissHref = CAMPAIGN_HOME, municipalityLabel, skip, trailingAction, contentAlign = 'start', contentFocus = 'title', children, }: CampaignWizardShellProps) => { const hasStepTitle = stepTitle != null && stepTitle !== '' const titleRef = useRef(null) const titleId = useId() const chrome = useMemo( () => toCampaignWizardChromeState({ flowTitle, isEntryStep, previousHref, dismissHref, municipalityLabel, skip, }), [dismissHref, flowTitle, isEntryStep, municipalityLabel, previousHref, skip], ) useSetCampaignWizardChrome(chrome) useEffect(() => { if (!hasStepTitle || contentFocus === 'none') return titleRef.current?.focus() }, [contentFocus, hasStepTitle, stepTitle]) return (
{trailingAction ?
{trailingAction}
: null}
{municipalityLabel ? (

{municipalityLabel}

) : null} {hasStepTitle ? (

{stepTitle}

) : null} {children}
) }