import React from 'react' import { Footprints, MoveRight, type LucideIcon } from 'lucide-react' import { useIsPhone } from '../../mobile/useIsPhone' /** * Shared display bits for public-transit entries (#1065) — the timeline row, * the Transports-tab card and the journey modal all render the same language: * "A → B" titles with a real arrow icon, and the leg sequence as chips where * walks carry their minutes (đŸš¶ 3 â€ș ⟹U2⟩ â€ș đŸš¶ 3) instead of a detached summary. */ export interface TransitLegDisplay { mode?: string line?: string | null line_color?: string | null line_text_color?: string | null duration?: number headsign?: string | null agency?: string | null stops?: number from?: { name?: string; time?: string | null; track?: string | null } to?: { name?: string; time?: string | null; track?: string | null } } /** * A walk leg as a one-line centred divider — dashed rules left and right, * the walk itself in the middle (đŸš¶ Walk to X · 4 min). Used by the journey * modal and the day-plan inline itinerary. */ export function TransitWalkDivider({ leg, t, size = 'md' }: { leg: TransitLegDisplay t: (k: string, p?: Record) => string size?: 'sm' | 'md' }) { const mins = leg.duration ? Math.round(leg.duration / 60) : null const isMobile = useIsPhone() // Hairlines that fade towards the outer edges — strongest next to the text. const rule = (dir: 'left' | 'right'): React.CSSProperties => ({ flex: 1, height: 1, minWidth: 12, borderRadius: 1, background: `linear-gradient(to ${dir}, var(--text-faint), transparent)`, opacity: 0.55, }) // On phones the minutes lead so a long stop name only ever clips the name. const text = isMobile ? `${mins ? `${t('transit.min', { count: mins })} · ` : ''}${t('transit.walkTo', { name: leg.to?.name || '' })}` : `${t('transit.walkTo', { name: leg.to?.name || '' })}${mins ? ` · ${t('transit.min', { count: mins })}` : ''}` return (
{text}
) } /** * The itinerary folded out right inside the day-plan row (#1065): one compact * line per leg — time, badge or foot icon, stations — sized for the sidebar. */ export function TransitItineraryInline({ legs, t }: { legs: TransitLegDisplay[] t: (k: string, p?: Record) => string }) { return (
{legs.map((leg, i) => { if (leg.mode === 'WALK') return const mins = leg.duration ? Math.round(leg.duration / 60) : null return (
{leg.from?.time || ''} {leg.line || leg.mode}
{leg.from?.name} {leg.to?.name}
{[ mins ? t('transit.min', { count: mins }) : null, leg.stops ? t('transit.stops', { count: leg.stops }) : null, leg.from?.track ? t('transit.platform', { track: leg.from.track }) : null, ].filter(Boolean).join(' · ')}
) })}
) } /** "1 h 9 min" / "42 min" from seconds — shared by all transit surfaces. */ export function fmtTransitDuration(seconds: number, t: (k: string, p?: Record) => string): string { const mins = Math.round(seconds / 60) if (mins < 60) return t('transit.min', { count: mins }) const h = Math.floor(mins / 60) const m = mins % 60 return m > 0 ? `${h} h ${m} min` : `${h} h` } export interface TransitMetaItem { icon?: LucideIcon text: string /** De-emphasised (operator names and the like). */ dim?: boolean /** Set in capitals, for a count with its unit ("15 MIN", "5 STOPS"). */ caps?: boolean } /** * A quiet badge row replacing dot-joined meta text ("21:06 - 22:15 - 69 min - * 14 stops ..."): each fact becomes a small chip, optional icon in front. */ export function TransitMetaBadges({ items, size = 'md' }: { items: TransitMetaItem[]; size?: 'sm' | 'md' }) { const font = size === 'sm' ? 'calc(10px * var(--fs-scale-caption, 1))' : 'calc(10.5px * var(--fs-scale-caption, 1))' return ( {items.filter(i => i.text).map(({ icon: Icon, text, dim, caps }, i) => ( {Icon && } {text} ))} ) } /** Renders "From → To" titles with an arrow icon instead of the text glyph. */ export function TransitTitle({ title, iconSize = 12 }: { title: string; iconSize?: number }) { const parts = title.split(' → ') if (parts.length < 2) return <>{title} return ( {parts.map((p, i) => ( {i > 0 && } {p} ))} ) } /** * The leg sequence as chips. Walk legs show their minutes right at the foot * icon (sub-minute walks are dropped); transit legs are line badges in their * colors. Optionally appends "· N transfers" — never a redundant "direct". */ export function TransitLegChips({ legs, transfers, size = 'sm', t }: { legs: TransitLegDisplay[] transfers?: number size?: 'sm' | 'md' t: (k: string, p?: Record) => string }) { const badgeFont = size === 'sm' ? 'calc(9.5px * var(--fs-scale-caption, 1))' : 'calc(10.5px * var(--fs-scale-caption, 1))' const walkIcon = size === 'sm' ? 10 : 12 const shown = legs.filter(l => l.mode !== 'WALK' || (l.duration || 0) >= 60) return ( {shown.map((leg, i) => ( {i > 0 && â€ș} {leg.mode === 'WALK' ? ( {Math.round((leg.duration || 0) / 60)} ) : ( {leg.line || leg.mode} )} ))} {typeof transfers === 'number' && transfers > 0 && ( · {t('transit.transfers', { count: transfers })} )} ) }