import { useState } from 'react' import { ChevronsDownUp, ChevronsUpDown, Download, Undo2, ArrowUpDown, Route as RouteIcon } from 'lucide-react' import { DayReorderPopup } from './DayReorderPopup' import Tooltip from '../shared/Tooltip' import { NEUTRAL_TINT, fs } from '../shared/DialogShell' import { BarButton, PANEL_BAR } from './planParts' import { useToast } from '../shared/Toast' import { TripExportModal } from './TripExportModal' import { isRoutableReservation } from '../../utils/reservationRoutes' import type { DayAddControls } from '../../utils/dayAdd' import type { DayDeleteQuestion } from '../../utils/dayImpactLines' import type { Trip, Day, Place, Category, AssignmentsMap, Reservation, DayNote } from '../../types' interface DayPlanSidebarToolbarProps { tripId: number trip: Trip days: Day[] places: Place[] categories: Category[] assignments: AssignmentsMap reservations: Reservation[] allConnectionsShown?: boolean onToggleAllConnections?: () => void dayNotes: Record t: (key: string, params?: Record) => string locale: string toast: ReturnType expandedDays: Set setExpandedDays: (next: Set) => void onUndo?: () => void canUndo: boolean undoHover: boolean setUndoHover: (v: boolean) => void lastActionLabel: string | null canEditDays?: boolean /** * Gates "Subscribe to calendar" in the export dialog only. Defaults to true so * a caller that has not wired the permission through keeps today's entries * rather than silently losing one. */ canManageShare?: boolean onReorderDays?: (orderedIds: number[]) => void onAddDay?: (position?: number) => void /** The planner's add controls: on a trip with dates the dialog offers the next date as well. */ dayAdd?: DayAddControls /** Asks to delete a day from the reorder dialog; without it the dialog has no delete buttons. */ onDeleteDay?: (dayId: number) => void /** The open delete question; the dialog asks it in place of its day list. */ deleteDayQuestion?: DayDeleteQuestion | null } export function DayPlanSidebarToolbar({ tripId, trip, days, places, categories, assignments, reservations, dayNotes, allConnectionsShown = false, onToggleAllConnections, t, locale, toast, expandedDays, setExpandedDays, onUndo, canUndo, undoHover, setUndoHover, lastActionLabel, canEditDays, canManageShare = true, onReorderDays, onAddDay, dayAdd, onDeleteDay, deleteDayQuestion, }: DayPlanSidebarToolbarProps) { const [reorderOpen, setReorderOpen] = useState(false) const [exportOpen, setExportOpen] = useState(false) const allExpanded = days.length > 0 && days.every(d => expandedDays.has(d.id)) const expandLabel = allExpanded ? t('dayplan.collapseAll') : t('dayplan.expandAll') const undoTip = canUndo && lastActionLabel ? t('undo.tooltip', { action: lastActionLabel }) : t('undo.button') const connectionsLabel = t(allConnectionsShown ? 'map.hideAllConnections' : 'map.showAllConnections') // The panel's head band: the export as its one labelled action, the tools as // quiet icons that rise like a filter tab when they are on. return (
{/* One export button instead of three: PDF, ICS and GPX each carried their own hover menu, and on a narrower sidebar the row ran out of width and pushed them off the edge. The dialog holds every option. */} setExportOpen(false)} tripId={tripId} trip={trip} days={days} places={places} categories={categories} assignments={assignments} reservations={reservations} dayNotes={dayNotes} t={t} locale={locale} toast={toast} canManageShare={canManageShare} /> {onUndo && ( )} { const next = allExpanded ? new Set() : new Set(days.map(d => d.id)) setExpandedDays(next) // Same store the sidebar reads on mount — a sessionStorage write // here left the persisted set behind after a reload. try { localStorage.setItem(`day-expanded-${tripId}`, JSON.stringify([...next])) } catch {} }} > {allExpanded ? : } {canEditDays && onReorderDays && onAddDay && days.length > 0 && ( <> setReorderOpen(v => !v)}> onAddDay()} dayAdd={dayAdd} onDeleteDay={onDeleteDay} deleteQuestion={deleteDayQuestion} onClose={() => setReorderOpen(false)} /> )} {onToggleAllConnections && reservations.some(isRoutableReservation) && ( )}
) }