'use client' import { CheckIcon, ChevronDownIcon } from 'lucide-react' import { useMemo, useState } from 'react' import { CampaignTransitionAnchor } from '@/components/campaign/shared/CampaignListPending' import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/Popover' import { useNarrowMeasured } from '@/hooks/use-mobile' import { cn } from '@/lib/utils' import { activityAgendaViewLabels, activityAgendaViews, buildActivityAgendaHref, type ActivityAgendaState, type ActivityAgendaView, } from '@/utilities/activityUi' /** * Mirrors the calendar's own mobile fallback (`MOBILE_BREAKPOINT_PX` in * `ActivityAgenda`): the selector's fallback label must agree with the view the * calendar will pick on a narrow screen. */ const NARROW_VIEWPORT_PX = 640 /** * C95 — the agenda-contextual view-mode selector rendered inside the app * header (desktop cluster / mobile top bar). Registered by `AgendaViewChrome`, * so it lives outside the page tree but navigates with the page's own URL * contract (`buildActivityAgendaHref`) and the shared list transition. */ export const AgendaViewSelector = ({ state }: { state: ActivityAgendaState }) => { const [open, setOpen] = useState(false) const { isNarrow, measured } = useNarrowMeasured(NARROW_VIEWPORT_PX) const effectiveView: ActivityAgendaView = state.view ?? (measured && isNarrow ? 'day' : 'week') const options = useMemo( () => activityAgendaViews.map((view) => ({ view, href: buildActivityAgendaHref({ ...state, view }), })), [state], ) const moveFocus = (event: React.KeyboardEvent, fromIndex: number) => { const direction = event.key === 'ArrowDown' || event.key === 'ArrowRight' ? 1 : event.key === 'Home' ? -2 : 0 const items = Array.from( event.currentTarget.querySelectorAll('[role="menuitemradio"]'), ) if (items.length === 0) return let next: number if (event.key === 'Home') next = 0 else if (event.key === 'End') next = items.length - 1 else if (direction !== 0) next = (fromIndex + direction + items.length) % items.length else return items[next]?.focus() event.preventDefault() } return ( ) }