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 (
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')}
}
>