import { importableTourTypeSchema, type TourLibraryItem, type TourTypeKey } from '@trek/shared'; import { AlertTriangle, CopyPlus, Library, Loader2, Search, WifiOff } from 'lucide-react'; import { useId } from 'react'; import { useTranslation } from '../../../i18n'; import { useSettingsStore } from '../../../store/settingsStore'; import { EditorField, INPUT, PillSelect } from '../../shared/dialogParts'; import { DialogButton, DialogFooter, DialogHeader, DialogShell, DialogTile, FooterSpacer, fs, NEUTRAL_TINT, } from '../../shared/DialogShell'; import { RailFacts, TourNotice } from '../tourParts'; import { tourPreviewFacts } from './tourPreviewFacts'; import { TourLinePreview, TourMeasurePills } from './tourPreviewParts'; import { type TourLibrary } from './useTourLibrary'; const ALL = 'all'; /** One tour of the list: its name, the trip it is in, its measures. */ function LibraryRow({ tour, selected, onChoose }: { tour: TourLibraryItem; selected: boolean; onChoose: () => void }) { const { t } = useTranslation(); return (
  • ); } /** A line of the list's state: loading, offline, failed with a retry, empty, or cut short. */ function ListState({ library }: { library: TourLibrary }) { const { t } = useTranslation(); const { listStatus, list } = library; if (listStatus === 'offline') return }>{t('tours.library.offline')}; if (listStatus === 'error') return ( }> {t('tours.library.loadFailed')} ); if (listStatus === 'loading' && !list) return (

    {t('common.loading')}

    ); if (list && list.tours.length === 0 && listStatus !== 'loading') return (

    {list.trips.length === 0 ? t('tours.library.noTrips') : t('tours.library.empty')}

    ); if (list?.truncated) return {t('tours.library.truncated')}; return null; } /** The search box and the two filters over the list. */ function ListFilters({ library }: { library: TourLibrary }) { const { t } = useTranslation(); const searchId = useId(); const trips = library.list?.trips ?? []; const tripOptions = [ { value: ALL, label: t('tours.library.allTrips') }, ...trips.map((trip) => ({ value: String(trip.id), label: trip.title, hint: String(trip.tour_count) })), ]; const typeOptions = [ { value: ALL, label: t('tours.library.allTypes') }, ...importableTourTypeSchema.options.map((type) => ({ value: type, label: t(`tourTypes.${type}`) })), ]; return (
    {library.listStatus === 'loading' ? ( ) : ( )} library.filter({ query: event.target.value })} placeholder={t('tours.library.search')} className="min-w-0 flex-1 border-0 bg-transparent text-content outline-none placeholder:text-content-faint" style={fs(12.5, 'body')} />
    library.filter({ tripFilter: value === ALL ? null : Number(value) })} /> library.filter({ typeFilter: value === ALL ? null : (value as TourTypeKey) })} />
    ); } /** The chosen tour: on a map, its facts, and the name the copy gets. */ function Preview({ library }: { library: TourLibrary }) { const { t } = useTranslation(); const unit = useSettingsStore((state) => state.settings.distance_unit) ?? 'metric'; const nameId = useId(); const { selected } = library; if (!selected) return (

    {t('tours.library.chooseHint')}

    ); return (
    library.setName(event.target.value)} />
    ); } /** * LIB-02: the dialog to take a tour of another trip over into this one. The * list on the left, the chosen tour on the right; the copy is made only by the * button in its foot. */ /** LIB-02: the dialog that takes a tour of another trip into this one, opened from "Add tour". */ export function TourLibraryDialog({ library }: { library: TourLibrary }) { const { t } = useTranslation(); const labelId = useId(); if (!library.open) return null; return ( } tint={NEUTRAL_TINT} labelId={labelId} onClose={library.close} eyebrow={t('tours.library.eyebrow')} title={t('tours.library.title')} sub={t('tours.library.sub')} subWraps /> } footer={ {t('common.cancel')} ) : ( ) } disabled={!library.canConfirm} onClick={() => void library.confirm()} > {t('tours.library.confirm')} } >
    {library.list && library.list.tours.length > 0 && (
      {library.list.tours.map((tour) => ( library.choose(tour)} /> ))}
    )}
    ); }