import { CalendarRange, Images, Info, Loader2, NotebookPen, Route } from 'lucide-react'; import type { ComponentType, ReactNode } from 'react'; import { useTranslation } from '../../i18n'; import { FROSTED_SHELL, segmentStyle } from '../Map/mapControlShadow'; import { LABEL, PopoverListPanel } from '../shared/dialogParts'; import { fs } from '../shared/DialogShell'; import { Tooltip } from '../shared/Tooltip'; import { usePopoverList } from '../shared/usePopoverList'; import { LAYER_TEXT, type JourneyMapLayerControl as Control, type JourneyMapLayer } from './journeyMapLayers'; import { PLAN_FALLBACK_COLOR } from './journeyMapMarks'; import type { JourneyMapLayersView } from './useJourneyMapLayers'; const ICONS: Record> = { plan: CalendarRange, recorded: Route, entries: NotebookPen, photos: Images, }; /** The sample colours of the key: an entry pin of the first day and a recorded line, as the map draws them. */ const SAMPLE_DAY = '#6366f1'; const SAMPLE_ROUTE = '#2563eb'; /** What a switch says about its layer: its name, and why it shows nothing when it does not. */ function hintOf(control: Control, t: (key: string, params?: Record) => string): string { const text = LAYER_TEXT[control.layer]; const name = t(text.labelKey); if (control.state === 'unavailable') return `${name}: ${t(text.unavailableKey)}`; if (control.state === 'empty') return `${name}: ${t(text.emptyKey)}`; if (control.state === 'loading') return `${name}: ${t('journey.map.layer.loading')}`; return name; } function LayerToggle({ control, on, onToggle, compact, }: { control: Control; on: boolean; onToggle: () => void; compact: boolean; }) { const { t } = useTranslation(); const Icon = ICONS[control.layer]; const name = t(LAYER_TEXT[control.layer].labelKey); const problem = control.state === 'unavailable'; // Nothing to draw: dimmed rather than gone, and the tooltip says why. const quiet = control.state === 'empty' || control.state === 'idle'; const showBadge = control.state === 'loading' || problem || (control.state === 'ready' && on); return ( ); } /** A hollow plan pin, as the map draws it. */ function PlanPinSample() { return ( ); } /** A journal entry's pin, with the plan's check when the plan had that place too. */ function EntryPinSample({ planned = false }: { planned?: boolean }) { return ( {planned && ( <> )} ); } function StaySample() { return ( ); } function SeveralSample() { return ( 3 ); } function LineSample({ dashed }: { dashed: boolean }) { return ( ); } const ROW = 'flex min-w-0 items-center gap-2.5 text-content-secondary'; /** * The key of the journey map: what each pin, dot and line stands for, with the * one rule that matters most: a planned place is no proof of a visit. */ function JourneyMapKey() { const { t } = useTranslation(); const rows: { sample: ReactNode; labelKey: string }[] = [ { sample: , labelKey: 'journey.map.legend.planned' }, { sample: , labelKey: 'journey.map.legend.entry' }, { sample: , labelKey: 'journey.map.legend.plannedWritten' }, { sample: , labelKey: 'journey.map.legend.stay' }, { sample: , labelKey: 'journey.map.legend.several' }, ]; return (
{t('journey.map.legend')}
    {rows.map((row) => (
  • {row.sample} {t(row.labelKey)}
  • ))}
{t('journey.map.legend.lines')}
  • {t('journey.map.legend.plannedRoute')}
  • {t('journey.map.legend.recordedRoute')}

{t('journey.map.legend.planIsNoVisit')}

); } function KeyButton() { const { t } = useTranslation(); const list = usePopoverList(-1, { estimatedHeight: 360 }); const { open, toggle, triggerRef, listId } = list; const label = t('journey.map.legend'); return ( <> ); } /** * The layer switches of a journey map (JRN-04), in the frosted pill the * planner's map controls wear: one per layer the reader is offered, each with * its count, a spinner while it loads and the warning tone when it could not * be read, and the key beside them. On a phone the switches drop their words; * the tooltip and the accessible name still say what each is. */ export default function JourneyMapLayerControl({ layers, compact = false, }: { layers: JourneyMapLayersView; compact?: boolean; }) { const { t } = useTranslation(); const live = layers.controls .filter((control) => control.state === 'loading' || control.state === 'unavailable') .map((control) => hintOf(control, t)) .join('. '); return (
{layers.controls.map((control) => ( layers.toggle(control.layer)} compact={compact} /> ))} {live}
); }