import type { PaddleRegionLoadState } from '@trek/shared'; import { CloudDownload, Hourglass, Loader2, Spline } from 'lucide-react'; import { useTranslation } from '../../../i18n'; import { fs } from '../../shared/DialogShell'; type Translate = ReturnType['t']; function headline(state: Extract, t: Translate) { const region = state.region.name; if (state.state === 'ready') return t('tours.paddle.load.ready', { region }); if (state.state === 'requested') return t('tours.paddle.load.requested', { region }); return t('tours.paddle.load.loading', { region }); } /** The phase of a load in words, with its share where it is known. */ function phaseText(state: Extract, t: Translate, language: string) { if (!state.progress) return state.ahead > 0 ? t('tours.paddle.load.waiting') : t('tours.paddle.load.phase.download'); const phase = t(`tours.paddle.load.phase.${state.progress.phase}`); const share = state.progress.fraction; return share === null ? phase : `${phase} ${new Intl.NumberFormat(language, { style: 'percent' }).format(share)}`; } /** * PAD-11C: a leg waiting for the water data of its region, which TREK loads * by itself or an admin has to let through. Calm, not red: nothing is wrong, * the data is on its way, and the leg is planned on its own once it is there. * Drawing it straight stays possible for whoever does not want to wait. */ export function PaddleRegionLoadRow({ state, disabled, onDrawStraight, }: { state: Extract; disabled: boolean; onDrawStraight: () => void; }) { const { t, language } = useTranslation(); const fraction = state.state === 'loading' ? (state.progress?.fraction ?? null) : state.state === 'ready' ? 1 : null; const busy = state.state !== 'requested'; return (
  • {busy ? ( {state.state === 'loading' && ( )} {state.state === 'requested' && state.reason !== 'ask' && ( {t(state.reason === 'too_large' ? 'tours.paddle.load.reason.tooLarge' : 'tours.paddle.load.reason.limit')} )} {state.state !== 'ready' && ( )}
  • ); }