teqo-backup/src/components/campaign/shell/CampaignMobileTopBar.tsx
Cursor Agent 962d704a54
B114: unify wizard Voltar header with Android back
Shared wizardBack contract + history layer (B106 pattern) so header
Voltar and popstate resolve the same navigate/pop-layer target.
Canonical previousHrefs; leadership form is a client history layer.

Co-authored-by: Francisco Solla <fsolla@users.noreply.github.com>
2026-08-02 00:46:45 +00:00

173 lines
6.1 KiB
TypeScript

'use client'
import { ArrowLeft, X } from 'lucide-react'
import type { ReactNode } from 'react'
import { useCampaignListTransition } from '@/components/campaign/shared/CampaignListPending'
import { CampaignWizardNavLink } from '@/components/campaign/shared/CampaignWizardNavLink'
import { useCampaignHomeSearchChrome } from '@/components/campaign/shell/CampaignHomeSearchChromeContext'
import {
useCampaignWizardChrome,
useCampaignWizardRequestBack,
} from '@/components/campaign/shell/CampaignWizardChromeContext'
import { Button } from '@/components/ui/button'
import { SidebarTrigger } from '@/components/ui/Sidebar'
import { Skeleton } from '@/components/ui/skeleton'
import { HOME_SEARCH_COLLAPSE_ARIA_LABEL } from '@/lib/campaignHomeSearchContract'
import {
WIZARD_APP_TOP_BAR_ARIA_LABEL,
WIZARD_DISMISS_ARIA_LABEL,
wizardFlowChromeAriaLabel,
wizardMunicipalityChromeAriaLabel,
} from '@/lib/campaignWizardCopy'
import { cn } from '@/lib/utils'
const wizardNavButtonClass =
'min-h-11 shrink-0 gap-1 px-2 text-primary-foreground hover:bg-primary-foreground/10 hover:text-primary-foreground'
const wizardDismissButtonClass =
'size-11 shrink-0 text-primary-foreground hover:bg-primary-foreground/10 hover:text-primary-foreground'
const wizardSkipButtonClass =
'min-h-11 max-w-[9rem] px-2 text-primary-foreground hover:bg-primary-foreground/10 hover:text-primary-foreground'
const wizardTitleSkeletonClass = 'mx-auto motion-reduce:animate-none bg-primary-foreground/20'
export const CampaignMobileTopBar = ({
notificationBell,
opsSyncStatus,
}: {
notificationBell?: ReactNode
/** OH5 — discreet sync chrome; only passed when OPS_HYBRID + staff. */
opsSyncStatus?: ReactNode
}) => {
const chrome = useCampaignWizardChrome()
const requestWizardBack = useCampaignWizardRequestBack()
const homeSearchChrome = useCampaignHomeSearchChrome()
const { isPending } = useCampaignListTransition()
if (chrome) {
return (
<header
data-slot="campaign-mobile-top-bar"
data-mode="wizard"
aria-label={wizardFlowChromeAriaLabel(chrome.flowTitle)}
className={cn(
'flex min-h-14 shrink-0 items-center gap-2 bg-primary px-2 text-primary-foreground md:hidden print:hidden',
'pt-[max(0px,env(safe-area-inset-top))]',
)}
>
<div className="flex min-w-0 flex-1 items-center">
{chrome.stepKind === 'continue' && chrome.previousHref ? (
<Button
type="button"
variant="ghost"
size="sm"
className={wizardNavButtonClass}
disabled={isPending}
onClick={requestWizardBack}
>
<ArrowLeft className="size-4 shrink-0" aria-hidden />
Voltar
</Button>
) : (
<div className="size-11 shrink-0" aria-hidden />
)}
<div className="min-w-0 flex-1 px-1 text-center leading-tight">
{isPending ? (
<>
<Skeleton className={cn(wizardTitleSkeletonClass, 'h-4 w-32 max-w-full')} />
{chrome.municipalityLabel ? (
<Skeleton className={cn(wizardTitleSkeletonClass, 'mt-1 h-3 w-24 max-w-full')} />
) : null}
</>
) : (
<>
<span className="block truncate text-sm font-semibold">{chrome.flowTitle}</span>
{chrome.municipalityLabel ? (
<span
className="block truncate text-xs text-primary-foreground/80"
aria-label={wizardMunicipalityChromeAriaLabel(chrome.municipalityLabel)}
>
{chrome.municipalityLabel}
</span>
) : null}
</>
)}
</div>
</div>
<div className="flex shrink-0 items-center">
{chrome.skip ? (
<Button
variant="ghost"
size="sm"
className={wizardSkipButtonClass}
asChild
disabled={isPending}
>
<CampaignWizardNavLink href={chrome.skip.href} title={chrome.skip.label}>
{chrome.skip.label}
</CampaignWizardNavLink>
</Button>
) : (
<Button
variant="ghost"
size="icon"
className={wizardDismissButtonClass}
asChild
disabled={isPending}
>
<CampaignWizardNavLink
href={chrome.dismissHref}
aria-label={WIZARD_DISMISS_ARIA_LABEL}
>
<X className="size-5" aria-hidden />
</CampaignWizardNavLink>
</Button>
)}
</div>
</header>
)
}
return (
<header
data-slot="campaign-mobile-top-bar"
data-mode="app"
data-home-search-focused={homeSearchChrome?.focused || undefined}
aria-label={WIZARD_APP_TOP_BAR_ARIA_LABEL}
className={cn(
'flex min-h-14 shrink-0 items-center gap-3 bg-primary px-4 text-primary-foreground md:hidden print:hidden',
'pt-[max(0px,env(safe-area-inset-top))]',
)}
>
{homeSearchChrome?.focused ? (
<Button
type="button"
variant="ghost"
size="sm"
className={wizardNavButtonClass}
aria-label={HOME_SEARCH_COLLAPSE_ARIA_LABEL}
onClick={homeSearchChrome.collapse}
>
<ArrowLeft className="size-4 shrink-0" aria-hidden />
Voltar
</Button>
) : (
<SidebarTrigger className="text-primary-foreground" />
)}
<div className="min-w-0 flex-1 leading-tight">
<span className="block truncate text-sm font-semibold">Jorge Solla</span>
<span className="block truncate text-xs text-primary-foreground/80">Campanha · Bahia</span>
{opsSyncStatus ? (
<div className="mt-0.5 text-primary-foreground/70 [&_[role=status]]:text-inherit">
{opsSyncStatus}
</div>
) : null}
</div>
{notificationBell ? <div className="shrink-0">{notificationBell}</div> : null}
</header>
)
}