'use client'; import { useState, useCallback } from 'react'; import { useDropzone } from 'react-dropzone'; import { motion, AnimatePresence } from 'framer-motion'; import { Upload, FileText, X, Loader2, CheckCircle2, AlertCircle } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { Card } from '@/components/ui/card'; import { Progress } from '@/components/ui/progress'; import { cn } from '@/lib/utils'; import { formatFileSize } from '@/lib/api'; interface PatentUploadProps { onUpload: (file: File) => Promise; uploading?: boolean; error?: string | null; } export function PatentUpload({ onUpload, uploading = false, error = null }: PatentUploadProps) { const [file, setFile] = useState(null); const [uploadProgress, setUploadProgress] = useState(0); const onDrop = useCallback((acceptedFiles: File[]) => { if (acceptedFiles.length > 0) { setFile(acceptedFiles[0]); } }, []); const { getRootProps, getInputProps, isDragActive, isDragReject } = useDropzone({ onDrop, accept: { 'application/pdf': ['.pdf'], }, maxSize: 50 * 1024 * 1024, // 50MB multiple: false, }); const handleUpload = async () => { console.log('🚀 handleUpload called!'); console.log('File:', file); if (!file) { console.error('❌ No file selected!'); return; } try { console.log('📤 Starting upload for:', file.name); // Simulate progress for UX (actual upload is handled by parent) setUploadProgress(0); const interval = setInterval(() => { setUploadProgress((prev) => { if (prev >= 90) { clearInterval(interval); return 90; } return prev + 10; }); }, 200); console.log('📡 Calling onUpload callback...'); await onUpload(file); clearInterval(interval); setUploadProgress(100); console.log('✅ Upload completed!'); } catch (err) { console.error('❌ Upload failed:', err); } }; const handleRemoveFile = () => { setFile(null); setUploadProgress(0); }; return (
{/* Dropzone */}
{isDragReject ? (

Invalid file type

Only PDF files up to 50MB are accepted

) : isDragActive ? (

Drop your patent here

) : (

Drag & drop your patent PDF here

or click to browse files (Max 50MB)

)}
PDF only
Max 50MB
{/* Selected File Display */} {file && (

{file.name}

{formatFileSize(file.size)}

{!uploading && uploadProgress === 0 && ( )} {uploading && ( )} {uploadProgress === 100 && ( )}
{/* Upload Progress */} {uploading && uploadProgress > 0 && uploadProgress < 100 && (

{uploadProgress}%

)}
)}
{/* Error Display */} {error && (

Upload Failed

{error}

)} {/* Upload Button */} {file && !uploading && uploadProgress === 0 && (
)}
); }