import { useMemo } from 'react' import { ChevronRight } from 'lucide-react' import { formatLocationName } from '../../utils/formatters' import { useTranslation } from '../../i18n' import JourneyMap from './JourneyMapAuto' import type { JourneyMapAutoHandle as JourneyMapHandle } from './JourneyMapAuto' import type { JourneyEntry } from '../../store/journeyStore' import { formatDate } from '../../pages/journeyDetail/JourneyDetailPage.helpers' export function MapView({ entries, mapEntries, sortedDates, activeLocationId, fullMapRef, onLocationClick }: { entries: JourneyEntry[] mapEntries: JourneyEntry[] sortedDates: string[] activeLocationId: string | null fullMapRef: React.RefObject onLocationClick: (id: string) => void }) { const { t, locale } = useTranslation() // group map entries by date const byDate = new Map() mapEntries.forEach((e, i) => { const d = e.entry_date if (!byDate.has(d)) byDate.set(d, []) byDate.get(d)!.push({ entry: e, globalIdx: i }) }) const dates = [...byDate.keys()].sort() // find first and last entry indices const firstId = mapEntries[0]?.id const lastId = mapEntries[mapEntries.length - 1]?.id const mapItems = useMemo(() => mapEntries.map(e => ({ id: String(e.id), lat: e.location_lat!, lng: e.location_lng!, title: e.title || '', mood: e.mood, entry_date: e.entry_date, })), [mapEntries]) return (
{/* Locations list */}
{/* Stats header */} {mapEntries.length > 0 && (
{[ { value: mapEntries.length, label: t('journey.stats.places') }, { value: dates.length, label: t('journey.stats.days') }, { value: entries.filter(e => e.type === 'entry').length, label: 'Stories' }, ].map(s => (
{s.value}
{s.label}
))}
)} {/* Day groups */}
{dates.map((date, dayIdx) => { const items = byDate.get(date)! const fd = formatDate(date, locale) return (
{/* Day separator */}
{t('journey.detail.day', { number: dayIdx + 1 })} {fd.month} {fd.day}
{/* Location items */} {items.map(({ entry: e, globalIdx }, itemIdx) => { const isActive = activeLocationId === String(e.id) const isFirst = e.id === firstId const isLast = e.id === lastId const showConnector = itemIdx < items.length - 1 return (
onLocationClick(String(e.id))} className={`flex items-center gap-3 p-3 rounded-[14px] cursor-pointer transition-all ${ isActive ? 'bg-zinc-100 dark:bg-zinc-800 border border-zinc-900 dark:border-zinc-100 translate-x-0.5' : 'bg-white dark:bg-zinc-900 border border-zinc-200 dark:border-zinc-700 hover:border-zinc-400 dark:hover:border-zinc-500 hover:translate-x-0.5' }`} > {/* Number badge */}
{globalIdx + 1}
{/* Info */}
{e.title || e.location_name}
{formatLocationName(e.location_name)}{e.entry_time ? ` ยท ${e.entry_time}` : ''}
{/* Chevron */}
{/* Connector line */} {showConnector && (
)}
) })}
) })}
) }