import type { CollectionFile, CollectionMapReadResult, CollectionMapSkipReason } from '@trek/shared'; import { Check, ChevronDown, Folder, Info, MapPin } from 'lucide-react'; import React, { useState } from 'react'; import type { TranslationFn } from '../../types'; import { fs } from '../shared/DialogShell'; /** Why a placemark was left out, in words; a switch, so a new reason does not build without them. */ function skipText(reason: CollectionMapSkipReason, t: TranslationFn): string { switch (reason) { case 'line': return t('collections.file.mapSkipLine'); case 'no_point': return t('collections.file.mapSkipNoPoint'); case 'invalid': return t('collections.file.mapSkipInvalid'); } } /** What a list file holds for a place; the file schema leaves its places to the server to check. */ type MapPlace = { name?: string; address?: string | null }; interface MapImportPreviewProps { file: CollectionFile; map: Pick; /** Indexes into `file.places` that will be imported. */ picked: Set; onToggle: (index: number) => void; onAll: (on: boolean) => void; t: TranslationFn; } /** * The places a KML or KMZ map holds, each one to keep or leave out (PLC-22), and * what did not become a place and why. Nothing is written before the import button, * so a map with a hundred pins can be narrowed to the six that matter first. */ export default function MapImportPreview({ file, map, picked, onToggle, onAll, t, }: MapImportPreviewProps): React.ReactElement { const [showSkipped, setShowSkipped] = useState(false); const all = picked.size === file.places.length; return (
{t('collections.file.mapPicked', { picked: picked.size, total: file.places.length })}
    {(file.places as MapPlace[]).map((place, index) => { const on = picked.has(index); const folder = map.folders[index]; return (
  • ); })}
{map.skipped.length > 0 && (
{showSkipped && (
    {map.skipped.map((entry, i) => (
  • {entry.name || t('collections.file.mapUnnamed')}: {skipText(entry.reason, t)}
  • ))}
)}
)}
); }