import { useRef, useState, useCallback } from 'react'; import { motion, AnimatePresence } from 'framer-motion'; import { Upload, FileImage, FileVideo, AlertCircle, Sparkles } from 'lucide-react'; import CameraCapture from './CameraCapture'; import styles from './UploadZone.module.css'; const MAX_SIZE_MB = 200; const ACCEPTED_IMAGE_TYPES = ['image/jpeg', 'image/png', 'image/webp', 'image/gif', 'image/tiff', 'image/avif']; const ACCEPTED_VIDEO_TYPES = ['video/mp4', 'video/webm', 'video/quicktime', 'video/x-msvideo', 'video/avi']; export default function UploadZone({ onFileSelect, error }) { const inputRef = useRef(null); const [isDragging, setIsDragging] = useState(false); const [dragType, setDragType] = useState(null); const [validationError, setValidationError] = useState(null); const validateFile = useCallback((file) => { if (!file) return 'No file selected'; const isImage = ACCEPTED_IMAGE_TYPES.includes(file.type) || file.type.startsWith('image/'); const isVideo = ACCEPTED_VIDEO_TYPES.includes(file.type) || file.type.startsWith('video/'); if (!isImage && !isVideo) return 'Unsupported file format. Please use an image or video file.'; if (file.size > MAX_SIZE_MB * 1024 * 1024) return `File is too large. Maximum size is ${MAX_SIZE_MB} MB.`; return null; }, []); const handleDragOver = useCallback((event) => { event.preventDefault(); const file = event.dataTransfer?.items?.[0]; if (!file) return; setIsDragging(true); if (file.type.startsWith('image/')) setDragType('image'); else if (file.type.startsWith('video/')) setDragType('video'); else setDragType('invalid'); }, []); const handleDragLeave = useCallback((event) => { event.preventDefault(); setIsDragging(false); setDragType(null); }, []); const handleDrop = useCallback((event) => { event.preventDefault(); setIsDragging(false); setDragType(null); const file = event.dataTransfer?.files?.[0]; if (!file) return; const validation = validateFile(file); if (validation) { setValidationError(validation); return; } setValidationError(null); onFileSelect(file); }, [validateFile, onFileSelect]); const handleInputChange = useCallback((event) => { const file = event.target.files?.[0]; if (!file) return; const validation = validateFile(file); if (validation) { setValidationError(validation); return; } setValidationError(null); onFileSelect(file); }, [validateFile, onFileSelect]); const handleClick = () => { setValidationError(null); inputRef.current?.click(); }; return (
Forensic-Grade AI Detection · Explainable Results

Is this media AI-generated?

Upload an image or video for multi-model forensic analysis. UAIDE detects deepfakes, GAN artifacts, and AI-generated content using Grad-CAM heatmaps and frequency analysis.

event.key === 'Enter' || event.key === ' ' ? handleClick() : null} initial={{ opacity: 0, scale: 0.97 }} animate={{ opacity: 1, scale: 1 }} transition={{ duration: 0.4, delay: 0.15 }} whileHover={{ scale: 1.005 }} > {isDragging ? ( {dragType === 'invalid' ? ( <>

Unsupported format

Drop images or video files only

) : ( <>
{dragType === 'video' ? : }

Release to analyse

{dragType === 'video' ? 'Video file detected' : 'Image file detected'}

)}
) : (

Drag & drop your media here

or browse files

Images JPEG · PNG · WebP · GIF · TIFF · AVIF
Videos MP4 · WebM · MOV · AVI

Max file size: {MAX_SIZE_MB} MB

)} {(validationError || error) && ( {validationError || error} )} {['GAN Detection', 'Diffusion Model ID', 'Grad-CAM Heatmap', 'FFT Analysis', 'Temporal Analysis', 'Deepfake Detection', 'Live Capture'].map((cap) => ( {cap} ))}
); }