import React from 'react' import { useRef, useId } from 'react' import { Check, FileDown, Loader2, Upload } from 'lucide-react' import { useTranslation } from '../../i18n' import { useToast } from '../shared/Toast' import { useTripStore } from '../../store/tripStore' import ToggleSwitch from '../Settings/ToggleSwitch' import { DialogButton, DialogFooter, DialogHeader, DialogSection, DialogShell, DialogTile, FooterSpacer, NEUTRAL_TINT, fs, } from '../shared/DialogShell' import { EditorField } from '../shared/dialogParts' import { usePlacesFileImport } from './usePlacesFileImport' interface FileImportModalProps { isOpen: boolean onClose: () => void tripId: number pushUndo?: (label: string, undoFn: () => Promise | void) => void initialFile?: File | null } /** One tickable kind of content in the file (waypoints, paths…). */ function TypeCheck({ checked, label, onToggle }: { checked: boolean; label: string; onToggle: () => void }) { return ( ) } const TYPE_BOX = 'flex flex-col gap-0.5 rounded-[14px] border border-edge-faint bg-surface-secondary p-1.5' export default function FileImportModal({ isOpen, onClose, tripId, pushUndo, initialFile }: FileImportModalProps) { const { t } = useTranslation() const toast = useToast() const loadTrip = useTripStore((s) => s.loadTrip) const fileInputRef = useRef(null) const titleId = useId() const { files, isDragOver, loading, error, summary, gpxOpts, toggleGpxOpt, kmlOpts, toggleKmlOpt, canEnrich: canEnrichImport, enrich, setEnrich, handleInputChange, handleDragOver, handleDragLeave, handleDrop, handleImport, close: handleClose, isGpx, isKml, gpxNoneSelected, kmlNoneSelected, canImport, } = usePlacesFileImport({ tripId, t, toast, loadTrip, pushUndo, onDone: onClose, variant: 'dialog', open: isOpen, initialFile, }) const enrichHintId = useId() if (!isOpen) return null let zoneText: React.ReactNode if (isDragOver) zoneText = {t('places.importFileDropActive')} else if (files.length > 0) zoneText = {files.map(f => f.name).join(', ')} else zoneText = {t('places.importFileDropHere')} return ( } tint={NEUTRAL_TINT} labelId={titleId} onClose={handleClose} title={t('places.importFile')} sub={t('places.importFileHint')} subWraps /> )} footer={( {t('common.cancel')} : undefined} > {loading ? t('common.loading') : t('common.import')} )} > {isGpx && (
{(['waypoints', 'routes', 'tracks'] as const).map(key => ( toggleGpxOpt(key)} label={t(key === 'waypoints' ? 'places.gpxImportWaypoints' : key === 'routes' ? 'places.gpxImportRoutes' : 'places.gpxImportTracks')} /> ))}
{gpxNoneSelected &&

{t('places.gpxImportNoneSelected')}

}
)} {isKml && (
{(['points', 'paths'] as const).map(key => ( toggleKmlOpt(key)} label={t(key === 'points' ? 'places.kmlImportPoints' : 'places.kmlImportPaths')} /> ))}
{kmlNoneSelected &&

{t('places.kmlImportNoneSelected')}

}
)} {canEnrichImport && ((isGpx && gpxOpts.waypoints) || (isKml && kmlOpts.points)) && (
{t('places.enrichOnImport')}
{t('places.enrichOnImportFileHint')}
setEnrich(v => !v)} label={t('places.enrichOnImport')} describedBy={enrichHintId} />
)} {summary && (
{t('places.kmlKmzSummaryValues', { total: summary.totalPlacemarks, created: summary.createdCount, skipped: summary.skippedCount, })}
{summary.warnings?.length > 0 && (
{summary.warnings.join('\n')}
)}
)} {error && (
{error}
)}
) }