import { useState } from "preact/hooks"; import type { Trip, Place } from "../../lib/types"; import type { UserLocation } from "../../lib/use-location"; import { PlaceCard } from "../shared/PlaceCard"; function buildVisitOrder(trip: Trip): Map { const order = new Map(); let idx = 0; for (const day of trip.days) { for (const stop of day.stops) { order.set(stop.name, idx++); } } return order; } export function LandmarksTab({ trip, location }: { trip: Trip; location: UserLocation | null }) { const [expandedIdx, setExpandedIdx] = useState(null); const visitOrder = buildVisitOrder(trip); const all = trip.places.filter(p => p.category === "landmark" || p.category === "trail"); const byName = new Map(); for (const p of all) { const existing = byName.get(p.name); if (!existing || p.category === "trail") byName.set(p.name, p); } const landmarks = [...byName.values()] .sort((a, b) => { const dayA = (a.details as Record)?.day as number ?? 99; const dayB = (b.details as Record)?.day as number ?? 99; if (dayA !== dayB) return dayA - dayB; const orderA = visitOrder.get(a.name) ?? 999; const orderB = visitOrder.get(b.name) ?? 999; return orderA - orderB; }); const byDay = new Map(); for (const p of landmarks) { const day = (p.details as Record)?.day as number ?? 0; const arr = byDay.get(day); if (arr) arr.push(p); else byDay.set(day, [p]); } return (
{landmarks.length} places
{[...byDay.entries()].sort((a, b) => a[0] - b[0]).map(([day, items]) => (
Day {day}
{items.map(place => { const uid = day + ":" + place.name; return ( setExpandedIdx(expandedIdx === uid ? null : uid)} location={location} /> ); })}
))} {landmarks.length === 0 && (
No landmarks found.
)}
); }