import type { TourTypeKey } from '@trek/shared'; import { MapPinned } from 'lucide-react'; import { useMemo, useState } from 'react'; import { useTranslation } from '../../i18n'; import { DialogButton } from '../shared/DialogShell'; import { NavigationMenu } from '../shared/NavigationMenu'; import { Tooltip } from '../shared/Tooltip'; import { tourRouteTargets } from './tourRouteApps'; /** * The tour's whole route, not only the way to its start, in the map apps that * follow one (#2812). Nothing when no app can take the tour. */ export function TourRouteAppsButton({ type, line, name, }: { type: TourTypeKey; line: ReadonlyArray | undefined; name: string; }) { const { t } = useTranslation(); const targets = useMemo(() => (line ? tourRouteTargets(type, line, name) : []), [type, line, name]); const [open, setOpen] = useState(false); // State, not a ref: the menu reads its anchor while rendering. const [anchor, setAnchor] = useState(null); if (targets.length === 0) return null; return ( <> setOpen((o) => !o)} aria-label={t('tours.detail.openRoute')} aria-haspopup="menu" aria-expanded={open} data-testid="tour-route-apps" icon={} > {t('tours.detail.mapsShort')} {open && setOpen(false)} />} ); }