import { useStore } from '../store' /** Format seconds into human-friendly string */ function formatTime(seconds) { if (seconds < 60) return `${Math.round(seconds)}s` if (seconds < 3600) return `${Math.round(seconds / 60)} min` const h = Math.floor(seconds / 3600) const m = Math.round((seconds % 3600) / 60) return m > 0 ? `${h}h ${m}m` : `${h}h` } /** Format distance in miles */ function formatDist(miles) { if (miles < 0.1) return `${Math.round(miles * 5280)} ft` return `${miles.toFixed(1)} mi` } /** Get a maneuver type icon */ function maneuverIcon(type) { switch (type) { case 0: return '→' // straight case 1: return '↗' // slight right case 2: return '→' // right case 3: return '↘' // sharp right case 4: return '↩' // u-turn right case 5: return '↩' // u-turn left case 6: return '↙' // sharp left case 7: return '←' // left case 8: return '↖' // slight left case 9: return '●' // depart case 10: return '●' // arrive (straight) case 11: return '●' // arrive (right) case 12: return '●' // arrive (left) case 15: return '◎' // roundabout enter case 16: return '◎' // roundabout exit case 24: return '▲' // merge case 25: return '⤴' // on ramp case 26: return '⤵' // off ramp default: return '→' } } export default function ManeuverList({ onManeuverClick }) { const route = useStore((s) => s.route) const routeLoading = useStore((s) => s.routeLoading) const routeError = useStore((s) => s.routeError) if (routeLoading) { return (
Calculating route...
) } if (routeError) { return (
{routeError}
) } if (!route || !route.legs) return null // Compute total summary const totalTime = route.summary?.time || 0 const totalDist = route.summary?.length || 0 // Flatten all maneuvers with cumulative time remaining const allManeuvers = [] let timeRemaining = totalTime for (let legIdx = 0; legIdx < route.legs.length; legIdx++) { const leg = route.legs[legIdx] for (const man of leg.maneuvers || []) { allManeuvers.push({ ...man, _legIndex: legIdx, timeRemaining, }) timeRemaining -= man.time || 0 } } return (
{/* Route summary */}
{formatDist(totalDist)} {formatTime(totalTime)}
{/* Maneuver steps */}
{allManeuvers.map((man, i) => ( ))}
) }