import { AlertTriangle, CheckCircle2, CopyPlus, Loader2, Replace, Route, X } from 'lucide-react'; import type { ReactNode } from 'react'; import { useTranslation } from '../../../i18n'; import { useSettingsStore } from '../../../store/settingsStore'; import { formatDistance } from '../../../utils/units'; import { DialogButton, fs } from '../../shared/DialogShell'; import { useToast } from '../../shared/Toast'; import { Tooltip } from '../../shared/Tooltip'; import { CardAction, RailCard, RailFacts, type TourMetricField } from '../tourParts'; import { CORRIDOR_M, FAITHFUL_SHARE } from './gpxConversion'; import type { GpxConversion } from './useGpxConversion'; /** The two lines of the comparison as the map draws them: the import dotted, the suggestion solid. */ function LineLegend() { const { t } = useTranslation(); return (
); } /** One line of status inside the card: an icon and a sentence. */ function StatusLine({ icon, tone = 'muted', children, }: { icon: ReactNode; tone?: 'muted' | 'warning'; children: ReactNode; }) { return (

{icon} {children}

); } /** * In the view of an import: plan an editable tour from it. Asked for, the * import's track turns into control points routed anew, and the card compares * that route to the track before anything is taken over. Taking it over either * plans the import over in place (its days and notes stay, the recorded track * is kept to go back to) or opens a new tour beside it. Both open in the editor * and are stored only when saved. */ export default function TourConversionSection({ conversion }: { conversion: GpxConversion }) { const { t } = useTranslation(); const toast = useToast(); const unit = useSettingsStore((state) => state.settings.distance_unit) ?? 'metric'; if (!conversion.available) return null; const adopt = (how: 'replace' | 'new') => { if (conversion.adopt(how)) toast.info(t(how === 'replace' ? 'tours.conversion.replacing' : 'tours.conversion.adopted')); }; const card = (children: ReactNode) => ( } title={t('tours.conversion.title')}> {children} ); if (conversion.status === 'idle') { return card(

{t( conversion.ski ? 'tours.conversion.introSki' : conversion.paddle ? 'tours.conversion.introPaddle' : 'tours.conversion.intro' )}

void conversion.analyze()} icon={}> {t('tours.conversion.analyze')}
); } if (conversion.status === 'analyzing') { return card( }> {t('tours.conversion.analyzing', { count: conversion.points.length })} ); } if (conversion.status === 'failed' || !conversion.comparison) { return card(
}> {t(conversion.error === 'track' ? 'tours.conversion.failedTrack' : 'tours.conversion.failedRouting')}
); } const { comparison } = conversion; const faithful = comparison.withinCorridor >= FAITHFUL_SHARE; const facts: TourMetricField[] = [ { label: t('tours.conversion.importLength'), value: formatDistance(comparison.originalKm, unit) }, { label: t('tours.conversion.suggestionLength'), value: formatDistance(comparison.suggestionKm, unit) }, { label: t('tours.conversion.withinCorridor', { m: CORRIDOR_M }), value: `${Math.round(comparison.withinCorridor * 100)} %`, }, { label: t('tours.conversion.maxDeviation'), value: `${Math.round(comparison.maxDeviationM)} m` }, { label: t('tours.conversion.controlPoints'), value: String(conversion.points.length) }, ]; return card(
) : ( ) } > {t( faithful ? conversion.paddle ? 'tours.conversion.closePaddle' : 'tours.conversion.close' : 'tours.conversion.different' )}
adopt('replace')} icon={} > {t('tours.conversion.replace')}
adopt('new')} icon={}> {t('tours.conversion.adopt')} }> {t('tours.conversion.discard')}
); }