import { Button } from '@/components/ui/button'; import { cn } from '@/lib/utils'; import { __ } from '@/utils/i18n'; import { FileSpreadsheet, Upload, X } from 'lucide-react'; import { useCallback, useState } from 'react'; interface ImportBalanceStepUploadProps { file: File | null; onFileSelect: (file: File) => void; onNext: () => void; onBack: () => void; } export function ImportBalanceStepUpload({ file, onFileSelect, onNext, onBack, }: ImportBalanceStepUploadProps) { const [isDragging, setIsDragging] = useState(false); const handleDragOver = useCallback((e: React.DragEvent) => { e.preventDefault(); setIsDragging(true); }, []); const handleDragLeave = useCallback((e: React.DragEvent) => { e.preventDefault(); setIsDragging(false); }, []); const isValidFile = useCallback( (file: File | null | undefined): boolean => { if (!file || !file.name) { return false; } const validExtensions = ['.csv', '.xls', '.xlsx']; const lastDotIndex = file.name.lastIndexOf('.'); if (lastDotIndex === -1) { return false; } const extension = file.name.toLowerCase().slice(lastDotIndex); return validExtensions.includes(extension); }, [], ); const handleDrop = useCallback( (e: React.DragEvent) => { e.preventDefault(); setIsDragging(false); const droppedFile = e.dataTransfer.files[0]; if (droppedFile && isValidFile(droppedFile)) { onFileSelect(droppedFile); } }, [onFileSelect, isValidFile], ); const handleFileInput = useCallback( (e: React.ChangeEvent) => { const selectedFile = e.target.files?.[0]; if (selectedFile && isValidFile(selectedFile)) { onFileSelect(selectedFile); } }, [onFileSelect, isValidFile], ); const formatFileSize = (bytes: number): string => { if (bytes < 1024) return bytes + ' B'; if (bytes < 1024 * 1024) return (bytes / 1024).toFixed(1) + ' KB'; return (bytes / (1024 * 1024)).toFixed(1) + ' MB'; }; return (
{!file ? ( <>

{__('Drop your file here, or click to browse')}

{__('Supports CSV, XLS, and XLSX files')}

) : (

{file.name}

{formatFileSize(file.size)}

)}
); }