import React, { useId, useMemo, useState } from 'react' import { Search, ArrowRight, Copy, CopyPlus, FolderInput, Loader2 } from 'lucide-react' import { DialogButton, DialogFooter, DialogHeader, DialogShell, DialogTile, FooterSpacer, NEUTRAL_TINT, fs } from '../shared/DialogShell' import { INPUT } from '../shared/dialogParts' import type { Collection } from '@trek/shared' import type { TranslationFn } from '../../types' interface MoveToListModalProps { mode: 'move' | 'copy' /** Candidate target lists (owned or shared with edit rights, excluding the current one). */ lists: Collection[] /** Number of selected places. */ count: number onPick: (targetId: number) => Promise | void onClose: () => void t: TranslationFn } /** * Target-list picker for moving or duplicating the selected places into another * of the user's lists. `mode` only changes the wording + the icons; the action * itself is the parent's onPick. */ export default function MoveToListModal({ mode, lists, count, onPick, onClose, t }: MoveToListModalProps): React.ReactElement { const [search, setSearch] = useState('') const [busy, setBusy] = useState(null) const labelId = useId() const filtered = useMemo(() => { const q = search.trim().toLowerCase() return q ? lists.filter(l => l.name.toLowerCase().includes(q)) : lists }, [lists, search]) const pick = async (id: number) => { if (busy != null) return setBusy(id) try { await onPick(id) } finally { setBusy(null) } } // The head tile repeats the icon of the selection bar button that opened the dialog. const Tile = mode === 'move' ? FolderInput : CopyPlus const Trailing = mode === 'move' ? ArrowRight : Copy return ( } tint={NEUTRAL_TINT} labelId={labelId} onClose={onClose} title={mode === 'move' ? t('collections.moveToListTitle', { count }) : t('collections.duplicateToListTitle', { count })} /> )} footer={( {t('common.cancel')} )} > {lists.length > 3 && (
)} {filtered.length === 0 ? (

{t('collections.noOtherLists')}

) : (
{filtered.map(list => { const isBusy = busy === list.id return ( ) })}
)}
) }