import { useState, useRef, useCallback } from "react"; import GlassContainer from "./GlassContainer"; import GlassButton from "./GlassButton"; import { GLASS_EFFECTS } from "../constants"; import type { VideoUploadState } from "../types"; interface VideoUploadScreenProps { onVideoReady: (videoState: VideoUploadState) => void; onBack: () => void; } export default function VideoUploadScreen({ onVideoReady, onBack }: VideoUploadScreenProps) { const [dragActive, setDragActive] = useState(false); const [uploadError, setUploadError] = useState(null); const [isProcessing, setIsProcessing] = useState(false); const fileInputRef = useRef(null); const handleFiles = useCallback(async (files: FileList | null) => { if (!files || files.length === 0) return; const file = files[0]; // Validate file type if (!file.type.startsWith('video/')) { setUploadError('Please select a valid video file.'); return; } // Validate file size (100MB limit) if (file.size > 1024 * 1024 * 1024) { setUploadError('Video file is too large. Please select a file under 1GB.'); return; } setIsProcessing(true); setUploadError(null); try { // Create video element const videoElement = document.createElement('video'); videoElement.muted = true; videoElement.controls = false; videoElement.preload = 'metadata'; // Create object URL for the video const videoUrl = URL.createObjectURL(file); videoElement.src = videoUrl; // Wait for video metadata to load await new Promise((resolve, reject) => { videoElement.onloadedmetadata = () => resolve(); videoElement.onerror = () => reject(new Error('Failed to load video')); videoElement.load(); }); // Validate video duration (max 10 minutes) if (videoElement.duration > 600) { setUploadError('Video is too long. Please select a video under 10 minutes.'); URL.revokeObjectURL(videoUrl); return; } const videoState: VideoUploadState = { file, videoElement, isReady: true }; onVideoReady(videoState); } catch (error) { console.error('Error processing video:', error); setUploadError('Failed to process video file. Please try a different file.'); } finally { setIsProcessing(false); } }, [onVideoReady]); const handleDrag = useCallback((e: React.DragEvent) => { e.preventDefault(); e.stopPropagation(); }, []); const handleDragIn = useCallback((e: React.DragEvent) => { e.preventDefault(); e.stopPropagation(); if (e.dataTransfer.items && e.dataTransfer.items.length > 0) { setDragActive(true); } }, []); const handleDragOut = useCallback((e: React.DragEvent) => { e.preventDefault(); e.stopPropagation(); setDragActive(false); }, []); const handleDrop = useCallback((e: React.DragEvent) => { e.preventDefault(); e.stopPropagation(); setDragActive(false); if (e.dataTransfer.files && e.dataTransfer.files.length > 0) { handleFiles(e.dataTransfer.files); } }, [handleFiles]); const handleFileSelect = useCallback(() => { fileInputRef.current?.click(); }, []); const handleFileChange = useCallback((e: React.ChangeEvent) => { handleFiles(e.target.files); }, [handleFiles]); return (
{/* Header */}

Upload Video

Select a video file to analyze with FastVLM

{/* Upload Area */}
{isProcessing ? (

Processing video...

Please wait while we prepare your video

) : (
{dragActive ? '📂' : '📁'}

{dragActive ? 'Drop your video here' : 'Upload Video File'}

Drag and drop a video file or click to browse

Supported formats: MP4, WebM, AVI, MOV

Maximum size: 100MB | Maximum duration: 10 minutes

Choose File
)} {uploadError && (

{uploadError}

)}
{/* Back Button */}
← Back to Options
{/* Hidden file input */}
); }