import React from 'react'; import { Folder, Loader2 } from 'lucide-react'; import { Button } from '../ui/button'; import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle } from '../ui/dialog'; import { Input } from '../ui/input'; import { cn } from '../../lib/utils'; // eslint-disable-next-line @typescript-eslint/no-explicit-any type SftpMoveToDialogProps = Record; export const SftpMoveToDialog: React.FC = ({ showMoveToDialog, setShowMoveToDialog, setMoveToPath, setMoveToError, setMoveToSuggestions, setMoveToSuggestionIndex, t, moveToInputRef, moveToPath, fetchMoveToSuggestions, moveToSuggestions, moveToSuggestionIndex, moveToError, isMoving, handleMoveToSubmit, }) => ( { if (!open) { setShowMoveToDialog(false); setMoveToSuggestions([]); setMoveToSuggestionIndex(-1); } }}> {t('sftp.moveTo.title')}
{ const val = e.target.value; setMoveToPath(val); setMoveToError(null); setMoveToSuggestionIndex(-1); fetchMoveToSuggestions(val); }} onKeyDown={(e) => { if (e.key === 'ArrowDown' && moveToSuggestions.length > 0) { e.preventDefault(); setMoveToSuggestionIndex((i) => i < moveToSuggestions.length - 1 ? i + 1 : 0); } else if (e.key === 'ArrowUp' && moveToSuggestions.length > 0) { e.preventDefault(); setMoveToSuggestionIndex((i) => i > 0 ? i - 1 : moveToSuggestions.length - 1); } else if (e.key === 'Tab' && moveToSuggestionIndex >= 0) { e.preventDefault(); const selected = moveToSuggestions[moveToSuggestionIndex]; setMoveToPath(selected); setMoveToError(null); fetchMoveToSuggestions(selected); } else if (e.key === 'Enter') { e.preventDefault(); if (moveToSuggestionIndex >= 0 && moveToSuggestions[moveToSuggestionIndex]) { const selected = moveToSuggestions[moveToSuggestionIndex]; setMoveToPath(selected); setMoveToSuggestionIndex(-1); setMoveToSuggestions([]); setMoveToError(null); } else { void handleMoveToSubmit(); } } else if (e.key === 'Escape') { if (moveToSuggestions.length > 0) { e.preventDefault(); e.stopPropagation(); setMoveToSuggestions([]); setMoveToSuggestionIndex(-1); } // When no suggestions, let the Dialog handle ESC to close itself } }} placeholder={t('sftp.moveTo.placeholder')} autoFocus className={moveToError ? 'border-destructive' : undefined} /> {moveToSuggestions.length > 0 && (
{moveToSuggestions.map((suggestion, i) => (
{ e.preventDefault(); setMoveToPath(suggestion); setMoveToSuggestions([]); setMoveToSuggestionIndex(-1); setMoveToError(null); }} > {suggestion}
))}
)}
{moveToError && (

{moveToError}

)}
);