import '../../styles/fadeEnd.css' import { useId, type ReactNode } from 'react' import { Eye, EyeOff } from 'lucide-react' import type { TourListItem } from '@trek/shared' import { fs } from '../shared/DialogShell' import { FoldButton, TourActivityBadge, TourCautionBadge, TourDaysBadge, TourGradeTile } from './tourParts' import type { Day } from '../../types' import { endPlaceDrag, startPlaceDrag } from '../Map/markerDrag' import { TourDayRowPills } from './TourDayRowFacts' import { StageCountCorner, TourStagesBadge } from './stages/StageParts' import { useTourDays } from './tourDays' import { Tooltip } from '../shared/Tooltip' import { useTranslation } from '../../i18n' const NO_DAYS: Day[] = [] interface TourListRowProps { tour: TourListItem /** The trip's days, to name the ones the tour is on; without them the row names none. */ days?: Day[] selected?: boolean disabled?: boolean /** The row can be picked up and dropped on a day of the plan, like a place. */ draggableToDay?: boolean onSelect: (tour: TourListItem, opener: HTMLElement) => void action?: ReactNode children?: ReactNode /** The colour the tour's line has on the map, shown beside it so the two read as one. */ trackColor?: string /** PR1-07: the person's switch for this tour's line on the trip map. */ mapToggle?: { hidden: boolean; onToggle: () => void; showLabel: string; hideLabel: string } /** MDT-02: a multi-day tour unfolds its stages below the row; `controls` is the id of what unfolds. */ fold?: { expanded: boolean; onToggle: () => void; label: string; controls: string } } /** The eye beside a row: shown on hover like the other actions, and always while the tour is hidden. */ function MapToggleButton({ toggle }: { toggle: NonNullable }) { const label = toggle.hidden ? toggle.showLabel : toggle.hideLabel return ( ) } /** The tile, the name, the description on a line of its own and one line of badges. */ function TourRowBody({ tour, nameId, tourDays, dimmed }: { tour: TourListItem nameId: string tourDays: ReturnType dimmed: boolean }) { return (
{tour.name} {tour.description && ( {tour.description} )} {/* One line of whole badges, most important first: one that does not fit wraps onto a second line the fixed height hides, so a narrow sidebar shows two and never half of one. The days come before the measures, so the ascent is what goes, never the days. */}
) } /** * The eye and the row's actions on the right. A hidden tour keeps its eye in * sight; the rest come out on hover, focus or selection, as a plan row's * controls do, so the name and badges have the room otherwise. */ function TourRowActions({ action, mapToggle, selected }: Pick & { selected: boolean }) { const hoverToggle = mapToggle && !mapToggle.hidden ? mapToggle : null return ( <> {mapToggle?.hidden && } {(action || hoverToggle) && (
event.stopPropagation()} className={`flex-none items-center gap-1.5 group-focus-within:flex group-hover:flex ${selected ? 'flex' : 'hidden'}`}> {hoverToggle && } {action}
)} ) } /** * MDT-02: how many stages the tour has, always in sight beside the row: on * the fold button where the row unfolds them, as a mark of its own otherwise. */ function TourRowStages({ tour, fold }: Pick) { const { t } = useTranslation() if (!fold) return const count = tour.stage_count ?? 0 return ( // Always in sight, unlike the hover actions: the stages are part of what the row is. event.stopPropagation()}> 0 ? : undefined} hint={count > 0 ? t('tours.stages.count', { count }) : undefined} /> ) } /** * A tour in a list, laid out like a stop in the day plan: its tile with the * grade, the name, the description below it, and one line of the plan's * white badges (time, distance, ascent, the days it is on, a caution). The day * and delete actions sit on the right. */ export default function TourListRow({ tour, days = NO_DAYS, selected = false, disabled = false, draggableToDay = false, onSelect, action, children, trackColor, mapToggle, fold }: TourListRowProps) { const nameId = useId() const tourDays = useTourDays(tour.place_id, days) const draggable = draggableToDay && !disabled const tone = selected ? 'bg-surface-selected' : disabled ? '' : 'hover:bg-surface-hover' const cursor = disabled ? 'cursor-default opacity-60' : draggable ? 'cursor-grab' : 'cursor-pointer' return (
  • startPlaceDrag(event.dataTransfer, tour.place_id) : undefined} onDragEnd={draggable ? endPlaceDrag : undefined} className={`group mx-1.5 rounded-[10px] px-1.5 py-2 outline-none transition-colors focus-visible:bg-surface-hover ${tone} ${cursor}`} onClick={event => { if (!disabled) onSelect(tour, event.currentTarget) }} onKeyDown={event => { if (disabled || event.target !== event.currentTarget) return if (event.key === 'Enter' || event.key === ' ') { event.preventDefault() onSelect(tour, event.currentTarget) } }} >
    {trackColor && ( // The line's colour on the map, as a plan row shows its category.
    {children}
  • ) }