The most complete open-source travel planner: real-time collaboration, bookings, budgets, packing lists, journals, offline PWA, SSO and an AI-ready MCP server, with planet-wide place search and routing built in.
TypeScript budget-trackercollaborativedockeritinerarymcp-serveroffline-firstopen-sourceopenstreetmappacking-listpwareal-timeself-hostedselfhostedtraveltravel-apptravel-journaltravel-plannertripitwanderlog
import { useEffect, useMemo } from 'react'
import { CalendarDays, Compass, Eraser, Hotel, MapPin, Pencil, Plus, RotateCcw, Route as RouteIcon, TramFront } from 'lucide-react'
import MSheet from '../../../components/MSheet'
import type { MTripSheetsProps } from '../MTripShell'
import { useTranslation } from '../../../../i18n'
import { useSettingsStore } from '../../../../store/settingsStore'
import { routeModeIcon, useRouteModeOptions } from '../../../../components/Planner/routeModes'
import { dayHeadingParts } from '../../../../utils/dayLabel'
import { stayDayTimes } from '../../../../components/Planner/stayDayTimes'
import { useDayNotes } from '../../../../hooks/useDayNotes'
import { useDayForecast, useDayRename } from '../../../../components/Planner/useDayDetail'
import { dayBookings, stayDayLabel, toDisplayTemp } from '../../../../components/Planner/dayDetailModel'
import { RES_ICONS, getNoteIcon } from '../../../../components/Planner/DayPlanSidebar.constants'
import { getDayBookendHotels, isDayInAccommodationRange } from '../../../../utils/dayOrder'
import { getTransportForDay, hasCarrierEndpointOnDay, pinnedAwayIn, stopDayIds } from '../../../../utils/dayMerge'
import { splitReservationDateTime } from '../../../../utils/formatters'
import { dayCoMapsUrl, dayGoogleMapsUrl, optimizeDayOrder } from '../../../../components/Planner/dayRoute'
import GoogleMapsIcon from '../../../../components/shared/GoogleMapsIcon'
import { BlurredCode } from '../../../../components/shared/BookingCode'
import { splitNoteTime } from '../lib/dayNotes'
import { weatherIconFor } from '../../../../components/Weather/weatherIcons'
import { dayWeatherAnchor } from '../../../../utils/dayWeather'
import type { Assignment, DayNote, Reservation } from '../../../../types'
import { Eyebrow, INNER_CLS, StatBox, TileHeader, displayTime } from './MTripSheetUi'
interface DaySheetPayload {
dayId?: number
}
/**
* Day-detail sheet ('day', glass card): 16-day weather (Open-Meteo via the
* weather service, climate fallback), the day's bookings and notes, the
* accommodation block and the day actions (rename, route on/off + profile,
* optimize, transit search, Google-Maps export).
*/
export default function MDaySheet({ planner, shell }: MTripSheetsProps) {
const { t, locale } = useTranslation()
const open = shell.sheet?.id === 'day'
const payload = (shell.sheet?.payload ?? {}) as DaySheetPayload
const dayId = payload.dayId ?? planner.selectedDayId
const day = planner.days.find(d => d.id === dayId) ?? null
const dayIndex = day ? planner.days.indexOf(day) : -1
const canEditDays = planner.can('day_edit', planner.trip)
const canEditReservations = planner.can('reservation_edit', planner.trip)
const tripHasDates = Boolean(planner.trip?.start_date && planner.trip?.end_date)
const routeProfileOptions = useRouteModeOptions()
const isFahrenheit = useSettingsStore(s => s.settings.temperature_unit) === 'fahrenheit'
const timeFormat = useSettingsStore(s => s.settings.time_format) || '24h'
const blurCodes = useSettingsStore(s => s.settings.blur_booking_codes)
const optimizeFromAccommodation = useSettingsStore(s => s.settings.optimize_from_accommodation)
const dateFirst = useSettingsStore(s => s.settings.day_date_first === true)
const dayAssignments = useMemo<Assignment[]>(() => {
if (!day) return []
return [...(planner.assignments[String(day.id)] || [])].sort((a, b) => a.order_index - b.order_index)
}, [day, planner.assignments])
// Weather anchor, day-local only (#2167): the day's first located stop, else the
// hotel you wake up in (unconditional bookend lookup, mirroring useMPlanTimeline).
// Never a place from another day — on a roadtrip that silently showed another
// city's weather with nothing naming the place.
const { lat, lng, name: weatherPlaceName } = dayWeatherAnchor(
dayAssignments,
() => (day ? getDayBookendHotels(day, planner.days, planner.tripAccommodations).morning : undefined),
)
const { weather, loading: weatherLoading } = useDayForecast(
open && !!day?.date && lat != null && lng != null, day?.date, lat, lng, planner.language,
)
// Inline rename — the day sheet owns the pencil on mobile (#1065 parity).
const { editingTitle, setEditingTitle, titleDraft, setTitleDraft, titleInputRef, startRename, commitRename } = useDayRename(title => {
if (day) planner.handleUpdateDayTitle(day.id, title)
})
useEffect(() => { if (!open) setEditingTitle(false) }, [open, setEditingTitle])
const notes = useDayNotes(planner.tripId)
const dayNotes: DayNote[] = day
? [...(notes.dayNotes[String(day.id)] || [])].sort((a, b) => (a.sort_order ?? 0) - (b.sort_order ?? 0))
: []
const dayReservations = useMemo(() => {
if (!day) return []
return dayBookings(day.id, dayAssignments, planner.reservations, pinnedAwayIn(planner.assignments, planner.days))
}, [day, planner.reservations, dayAssignments, planner.assignments, planner.days])
const dayAccommodations = useMemo(() => {
if (!day) return []
return planner.tripAccommodations.filter(a =>
isDayInAccommodationRange(day, a.start_day_id, a.end_day_id, planner.days),
)
}, [day, planner.tripAccommodations, planner.days])
const routedStops = dayAssignments.filter(a => a.place?.lat != null && a.place?.lng != null)
const bookends = day && optimizeFromAccommodation !== false
? getDayBookendHotels(day, planner.days, planner.tripAccommodations)
: null
const routable = routedStops.length >= 2 || (routedStops.length >= 1 && !!bookends?.morning)
const routeActive = planner.routeShown && planner.selectedDayId === day?.id
const toggleRoute = () => {
if (!day) return
if (planner.selectedDayId === day.id) {
planner.setRouteShown(v => !v)
} else {
planner.handleSelectDay(day.id, true)
if (!planner.routeShown) planner.setRouteShown(true)
}
}
// A booking opens its detail sheet, as on the desktop; its pencil edits it there.
const openReservation = (r: Reservation) => {
const isTransport = planner.TRANSPORT_TYPES.has(r.type)
if (isTransport ? !canEditDays : !canEditReservations) return
shell.openSheet('transport', { reservationId: r.id })
}
const planTransit = () => {
if (!day) return
planner.setTransportModalDayId(day.id)
planner.setEditingTransport(null)
planner.setTransitPrefill(null)
planner.setTransportModalAutomated(true)
planner.setShowTransportModal(true)
shell.closeSheet()
}
// Same optimizer as the desktop day plan: timed places stay anchored, the
// rest is rerouted (optionally hotel-bookended); handleReorder owns the undo.
const optimizeDay = () => {
if (!day || dayAssignments.length < 3) return
const result = optimizeDayOrder(
day, planner.days, dayAssignments, planner.tripAccommodations, optimizeFromAccommodation !== false, dayHasCarrier,
)
if (!result) return
planner.handleReorder(day.id, result.order.map(a => a.id))
planner.toast.success(result.usedHotel
? t('dayplan.toast.routeOptimizedFromHotel')
: t('dayplan.toast.routeOptimized'))
}
// Carrier evidence for the export bookends (#2157) — via the span-aware transport
// filter the timeline uses, not dayReservations above, which matches on day_id
// only and would miss an overnight carrier that merely arrives today.
const dayHasCarrier = useMemo(() => {
if (!day) return false
return getTransportForDay({
reservations: planner.reservations,
dayId: day.id,
dayAssignmentIds: dayAssignments.map(a => a.id),
days: planner.days,
stopDays: stopDayIds(planner.assignments),
}).some(r => hasCarrierEndpointOnDay(r, day.id))
}, [day, planner.reservations, planner.days, dayAssignments, planner.assignments])
// Google-Maps export of the day's stops, hotel-bookended like the drawn route (#1372/#1465).
const openInGoogleMaps = () => {
if (!day) return
const url = dayGoogleMapsUrl(
day, planner.days, dayAssignments, planner.tripAccommodations, optimizeFromAccommodation !== false,
{ located: dayHasCarrier },
)
if (url) window.open(url, '_blank', 'noopener,noreferrer')
}
// The same day in CoMaps, for navigating it offline (#1904).
const openInCoMaps = () => {
if (!day) return
const url = dayCoMapsUrl(
day, planner.days, dayAssignments, planner.tripAccommodations, optimizeFromAccommodation !== false,
day.default_transport_mode ?? planner.routeProfile, { located: dayHasCarrier },
)
if (url) window.open(url, '_blank', 'noopener,noreferrer')
}
const addAccommodation = () => {
if (!day) return
shell.openSheet('accommodation', { dayId: day.id })
}
// Tapping the stay opens the stay. It used to open the place the stay is
// pinned to, which put check-in/check-out/confirmation out of reach entirely —
// MAccommodationSheet has taken an accId all along, nothing ever passed one (#2001).
const editAccommodation = (accId: number) => {
if (!day) return
shell.openSheet('accommodation', { dayId: day.id, accId })
}
const openAccommodationPlace = (placeId: number) => {
shell.closeSheet()
planner.handlePlaceClick(placeId)
}
const cTemp = (c: number) => toDisplayTemp(c, isFahrenheit)
const formattedDate = day?.date
? new Date(`${day.date.slice(0, 10)}T00:00:00Z`).toLocaleDateString(locale, {
weekday: 'long', day: 'numeric', month: 'long', timeZone: 'UTC',
})
: null
// A day_number of 0 is as unusable as a missing one — both fall back to the row position.
const dayLabel = day?.title || t('planner.dayN', { n: day ? day.day_number || dayIndex + 1 : '?' })
const heading = dayHeadingParts(dayLabel, formattedDate, dateFirst)
// The input takes the size of the line it edits: the heading, or the line under the date.
const titleInput = (lead: boolean) => (
<input
ref={titleInputRef}
value={titleDraft}
onChange={e => setTitleDraft(e.target.value)}
onBlur={commitRename}
onKeyDown={e => { if (e.key === 'Enter') commitRename(); if (e.key === 'Escape') setEditingTitle(false) }}
placeholder={t('planner.dayN', { n: dayIndex + 1 })}
className={`w-full border-b-[1.5px] border-[color:var(--m-ink)] bg-transparent p-0 font-[inherit] outline-none ${lead ? 'text-[1.0625rem] font-bold' : ''}`}
/>
)
const renamePencil = canEditDays && day && (
<button
type="button"
onClick={() => startRename(day.title || '')}
aria-label={t('mobileTrip.renameDay')}
className="flex flex-none p-[3px] text-m-faint"
>
<Pencil size={12} strokeWidth={1.8} />
</button>
)
const WeatherIcon = weatherIconFor(weather?.main)
const stayBadge = (acc: (typeof dayAccommodations)[number]) => {
const label = stayDayLabel(acc, day?.id, t)
if (label && acc.start_day_id === day?.id) return { label, cls: 'border-[color:var(--m-st-confirmed)] text-[color:var(--m-st-confirmed)]' }
if (label) return { label, cls: 'border-[color:var(--m-st-danger)] text-[color:var(--m-st-danger)]' }
return { label: t('mobileTrip.stay'), cls: 'border-[color:var(--m-faint)] text-m-muted' }
}
return (
<MSheet open={open && !!day} onClose={shell.closeSheet} variant="card" material="glass" ariaLabel={dayLabel}>
{day && (
<>
<div className="flex-none px-[18px] pt-4">
{/* The pencil and the input go with the name: under the date when it leads (#2921). */}
<TileHeader
icon={<CalendarDays size={19} strokeWidth={1.8} />}
title={editingTitle && heading.nameFirst ? (
titleInput(true)
) : (
<>
<span className="truncate">{heading.primary}</span>
{heading.nameFirst && renamePencil}
</>
)}
sub={!heading.nameFirst && heading.secondary ? (
editingTitle ? titleInput(false) : (
<span className="flex min-w-0 items-center gap-1">
<span className="truncate">{heading.secondary}</span>
{renamePencil}
</span>
)
) : heading.secondary}
onClose={shell.closeSheet}
closeLabel={t('common.close')}
/>
</div>
<div className="m-scroll-fade mt-2 min-h-0 flex-1 overflow-y-auto px-[18px] pb-[18px] pt-[14px]">
{/* ── Weather (16-day forecast, climate fallback) ── */}
{day.date && lat != null && lng != null && (
weatherLoading ? (
<div className="mt-[14px] flex items-center gap-3">
<div className="h-8 w-8 animate-pulse rounded-[10px] bg-[color:var(--m-ic)]" />
<div className="h-6 w-24 animate-pulse rounded-[8px] bg-[color:var(--m-ic)]" />
</div>
) : weather ? (
<div className="mt-[14px]">
<div className="flex items-center gap-3">
<WeatherIcon size={32} strokeWidth={1.6} />
<span className="text-[2rem] font-bold leading-none">
{weather.type === 'climate' ? 'Ø ' : ''}{cTemp(weather.temp)}°
</span>
<span className="min-w-0 font-geist text-[0.75rem] text-m-muted">
{weather.temp_max != null && weather.temp_min != null && (
<>{cTemp(weather.temp_max)}° / {cTemp(weather.temp_min)}° · </>
)}
<span className="capitalize">{weather.description}</span>
</span>
</div>
{/* Which place the forecast is for — on a roadtrip "the day's
weather" is ambiguous without it (#2167). */}
{weatherPlaceName && (
<div className="mt-[6px] font-geist text-[0.625rem] text-m-faint">
{t('day.weatherFor', { name: weatherPlaceName })}
</div>
)}
{weather.type === 'climate' && (
<div className="mt-[6px] font-geist text-[0.625rem] italic text-m-faint">{t('day.climateHint')}</div>
)}
</div>
) : (
<div className="mt-[14px] font-geist text-[0.75rem] text-m-faint">{t('day.noWeather')}</div>
)
)}
{/* ── Day actions: route / Google Maps / optimize / profile / transit ── */}
{(routable || canEditDays) && (
<div className="mt-[14px] flex flex-wrap items-center gap-[7px]">
{routable && (
<button
type="button"
onClick={toggleRoute}
aria-pressed={routeActive}
className={`flex items-center gap-[5px] rounded-full px-3 py-[7px] text-[0.75rem] font-semibold ${
routeActive ? 'bg-m-act text-m-actfg' : `${INNER_CLS} text-m-ink`
}`}
>
<RouteIcon size={13} strokeWidth={2} />
{t('dayplan.route')}
</button>
)}
{routable && (
<div className={`flex overflow-hidden rounded-full ${INNER_CLS}`}>
{routeProfileOptions.map(p => {
const ProfileIcon = routeModeIcon(p.key)
const active = planner.routeProfile === p.key
return (
<button
key={p.key}
type="button"
onClick={() => planner.setRouteProfile(p.key)}
aria-label={p.label}
title={p.label}
aria-pressed={active}
className={`flex items-center px-[10px] py-[7px] ${active ? 'bg-m-act text-m-actfg' : 'text-m-muted'}`}
>
<ProfileIcon size={13} strokeWidth={2} />
</button>
)
})}
</div>
)}
{routable && (
<button
type="button"
onClick={openInGoogleMaps}
className={`flex items-center gap-[5px] rounded-full px-3 py-[7px] text-[0.75rem] font-semibold text-m-ink ${INNER_CLS}`}
>
<GoogleMapsIcon size={13} />
{t('planner.openGoogleMaps')}
</button>
)}
{routable && (
<button
type="button"
onClick={openInCoMaps}
className={`flex items-center gap-[5px] rounded-full px-3 py-[7px] text-[0.75rem] font-semibold text-m-ink ${INNER_CLS}`}
>
<Compass size={13} strokeWidth={2} />
{t('planner.openCoMaps')}
</button>
)}
{canEditDays && dayAssignments.length >= 3 && (
<button
type="button"
onClick={optimizeDay}
className={`flex items-center gap-[5px] rounded-full px-3 py-[7px] text-[0.75rem] font-semibold text-m-ink ${INNER_CLS}`}
>
<RotateCcw size={13} strokeWidth={2} />
{t('dayplan.optimize')}
</button>
)}
{canEditDays && dayAssignments.length > 0 && (
<button
type="button"
onClick={() => planner.handleClearDay(day.id)}
className={`flex items-center gap-[5px] rounded-full px-3 py-[7px] text-[0.75rem] font-semibold text-m-ink ${INNER_CLS}`}
>
<Eraser size={13} strokeWidth={2} />
{t('dayplan.clearDay')}
</button>
)}
{canEditDays && tripHasDates && (
<button
type="button"
onClick={planTransit}
className={`flex items-center gap-[5px] rounded-full px-3 py-[7px] text-[0.75rem] font-semibold text-m-ink ${INNER_CLS}`}
>
<TramFront size={13} strokeWidth={2} />
{t('transit.title')}
</button>
)}
</div>
)}
{/* ── Bookings of the day ── */}
{dayReservations.length > 0 && (
<>
<Eyebrow className="mb-[6px] mt-[14px]">{t('day.reservations')}</Eyebrow>
<div className="flex flex-col gap-[6px]">
{dayReservations.map(r => {
const ResIcon = RES_ICONS[r.type as keyof typeof RES_ICONS] || RES_ICONS.other
const { time: startTime } = splitReservationDateTime(r.reservation_time)
const { time: endTime } = splitReservationDateTime(r.reservation_end_time)
return (
<button
key={r.id}
type="button"
onClick={() => openReservation(r)}
className={`flex w-full items-center gap-[10px] rounded-[13px] px-[11px] py-[9px] text-start ${INNER_CLS}`}
>
<ResIcon size={15} strokeWidth={2} className="flex-none text-m-muted" />
<span dir="auto" className="min-w-0 flex-1 truncate text-[0.8125rem] font-semibold">{r.title}</span>
{(startTime || endTime) && (
<span className="flex-none font-geist text-[0.6875rem] tabular-nums text-m-muted">
{startTime ? displayTime(startTime, locale, timeFormat) : ''}
{endTime ? ` – ${displayTime(endTime, locale, timeFormat)}` : ''}
</span>
)}
</button>
)
})}
</div>
</>
)}
{/* ── Day notes ── */}
{(dayNotes.length > 0 || canEditDays) && (
<>
<div className="mb-[6px] mt-[14px] flex items-center">
<Eyebrow>{t('mobileTrip.notes')}</Eyebrow>
{canEditDays && (
<button
type="button"
onClick={() => shell.openSheet('note', { dayId: day.id })}
aria-label={t('dayplan.addNote')}
className="ms-auto flex h-6 w-6 items-center justify-center rounded-full bg-[color:var(--m-ic)] text-m-muted"
>
<Plus size={12} strokeWidth={2.2} />
</button>
)}
</div>
{dayNotes.length > 0 && (
<div className="flex flex-col gap-[6px]">
{dayNotes.map(note => {
const NoteIcon = getNoteIcon(note.icon)
// The time column is a free detail line; only a leading
// HH:MM renders as an actual time (desktop semantics).
const { time: noteTime, detail } = splitNoteTime(note.time)
return (
<button
key={note.id}
type="button"
onClick={() => { if (canEditDays) shell.openSheet('note', { dayId: day.id, note }) }}
className={`flex w-full items-center gap-[10px] rounded-[13px] px-[11px] py-[9px] text-start ${INNER_CLS}`}
>
<NoteIcon size={15} strokeWidth={1.8} className="flex-none text-m-muted" />
<span className="min-w-0 flex-1">
<span className="block truncate text-[0.8125rem] font-semibold">{note.text}</span>
{detail && (
<span className="block truncate font-geist text-[0.65625rem] text-m-muted">{detail}</span>
)}
</span>
{noteTime && (
<span className="flex-none font-geist text-[0.6875rem] tabular-nums text-m-muted">
{displayTime(noteTime, locale, timeFormat)}
</span>
)}
</button>
)
})}
</div>
)}
</>
)}
{/* ── Accommodation ── */}
<Eyebrow className="mb-[6px] mt-[14px]">{t('day.accommodation')}</Eyebrow>
{dayAccommodations.length > 0 && (
<div className="flex flex-col gap-2">
{dayAccommodations.map(acc => {
const badge = stayBadge(acc)
const times = stayDayTimes(acc, day.id)
// The desk time carries the arrival or departure colour itself (#2393),
// so the head keeps its room for the name and drops the badge.
const badgeAtTime = times.checkIn || times.checkOut
const linked = planner.reservations.find(r => String(r.accommodation_id ?? '') === String(acc.id))
return (
<div key={acc.id} className={`rounded-[16px] px-3 py-[11px] ${INNER_CLS}`}>
<div className="flex items-center gap-[10px]">
<button
type="button"
onClick={() => {
if (canEditDays) editAccommodation(acc.id)
else if (acc.place_id) openAccommodationPlace(acc.place_id)
}}
className="flex min-w-0 flex-1 items-center gap-[10px] text-start"
>
{acc.place_image ? (
<div
className="h-10 w-10 flex-none rounded-[12px] bg-cover bg-center"
style={{ backgroundImage: `url('${acc.place_image}')` }}
/>
) : (
<div className="flex h-10 w-10 flex-none items-center justify-center rounded-[12px] bg-[color:var(--m-ic)]">
<Hotel size={17} strokeWidth={1.8} className="text-m-muted" />
</div>
)}
<div className="min-w-0 flex-1">
<div dir="auto" className="truncate text-[0.875rem] font-semibold">{acc.place_name}</div>
{acc.place_address && (
<div dir="auto" className="truncate font-geist text-[0.65625rem] text-m-muted">{acc.place_address}</div>
)}
</div>
</button>
{!badgeAtTime && (
<span className={`flex-none rounded-full border px-[7px] py-[2px] text-[0.5625rem] font-bold uppercase tracking-[.05em] ${badge.cls}`}>
{badge.label}
</span>
)}
{canEditDays && acc.place_id != null && (
<button
type="button"
onClick={() => openAccommodationPlace(acc.place_id as number)}
aria-label={t('mobileTrip.viewDetails')}
className="flex flex-none p-[3px] text-m-faint"
>
<MapPin size={13} strokeWidth={1.8} />
</button>
)}
</div>
{(badgeAtTime || acc.confirmation) && (
<div className="mt-[10px] flex gap-[6px]">
{times.checkIn && acc.check_in && (
<StatBox
value={`${displayTime(acc.check_in, locale, timeFormat)}${acc.check_in_end ? ` – ${displayTime(acc.check_in_end, locale, timeFormat)}` : ''}`}
label={t('day.checkIn')}
labelTone="confirmed"
/>
)}
{times.checkOut && acc.check_out && (
<StatBox value={displayTime(acc.check_out, locale, timeFormat)} label={t('day.checkOut')} labelTone="danger" />
)}
{acc.confirmation && (
<StatBox value={acc.confirmation} label={t('day.confirmation')} blurred={blurCodes} />
)}
</div>
)}
{linked && (
// The day's booking list filters hotels out, so this strip is
// the only place the stay's booking shows up — it may as well open it.
<button
type="button"
onClick={() => openReservation(linked)}
className="mt-2 flex w-full items-center gap-2 text-start"
>
<span
className="h-2 w-2 flex-none rounded-full"
style={{ background: linked.status === 'confirmed' ? 'var(--m-st-confirmed)' : 'var(--m-st-pending)' }}
/>
<span className="min-w-0 flex-1 truncate font-geist text-[0.6875rem] text-m-muted">
{linked.status === 'confirmed' ? t('reservations.confirmed') : t('reservations.pending')}
{/* The strip is a button already, so the code gets the plain blur, not a toggle. */}
{linked.confirmation_number ? <> · <BlurredCode interactive={false}>{`#${linked.confirmation_number}`}</BlurredCode></> : ''}
</span>
</button>
)}
</div>
)
})}
</div>
)}
{canEditDays && (
<button
type="button"
onClick={addAccommodation}
className="mt-[10px] flex w-full items-center justify-center gap-[6px] rounded-[13px] border-[1.5px] border-dashed border-[color:var(--m-faint)] py-[9px] text-[0.75rem] font-semibold text-m-muted"
>
<Plus size={13} strokeWidth={2.2} />
{t('day.addAccommodation')}
</button>
)}
</div>
</>
)}
</MSheet>
)
}