import { useState, useRef, ChangeEvent } from "react"; import { Download, Play, FileUp, Sparkles, Cpu, CheckCircle, RefreshCw, FileText, Image as ImageIcon, Video, Music } from "lucide-react"; import { motion, AnimatePresence } from "motion/react"; interface HeroProps { downloadUrl: string; } const PRESET_FILES = [ { name: "quarterly_report.docx", size: "2.4 MB", type: "document" }, { name: "product_photo.png", size: "8.1 MB", type: "image" }, { name: "marketing_pitch.mp4", size: "45.2 MB", type: "video" }, { name: "intro_music.mp3", size: "5.7 MB", type: "audio" }, ]; const CONVERSION_OPTIONS: Record = { document: ["PDF Document (.pdf)", "Markdown Text (.md)", "eBook (.epub)", "Web Page (.html)"], image: ["WebP Image (.webp)", "JPEG Premium (.jpg)", "PNG Lossless (.png)", "PDF Page (.pdf)"], video: ["MP4 Video (.mp4)", "GIF Animation (.gif)", "MP3 Audio (.mp3)", "AVI Format (.avi)"], audio: ["WAV Lossless (.wav)", "AAC Advanced (.aac)", "MP3 Standard (.mp3)", "FLAC Studio (.flac)"], }; export default function Hero({ downloadUrl }: HeroProps) { const [selectedFile, setSelectedFile] = useState(PRESET_FILES[1]); // default to image const [targetFormat, setTargetFormat] = useState("WebP Image (.webp)"); const [isConverting, setIsConverting] = useState(false); const [progress, setProgress] = useState(0); const [gpuLoad, setGpuLoad] = useState(0); const [isConverted, setIsConverted] = useState(false); const [showNotification, setShowNotification] = useState(false); // drag state const [isDragOver, setIsDragOver] = useState(false); const fileInputRef = useRef(null); // handle preset selection const selectPreset = (file: typeof PRESET_FILES[0]) => { if (isConverting) return; setSelectedFile(file); setIsConverted(false); setProgress(0); // set first formatting option as default const options = CONVERSION_OPTIONS[file.type]; setTargetFormat(options[0]); }; // simulate conversion const handleConvert = () => { if (!selectedFile || isConverting) return; setIsConverting(true); setIsConverted(false); setProgress(0); const interval = setInterval(() => { setProgress((prev) => { // dynamic GPU metrics simulate load setGpuLoad(Math.floor(Math.random() * 35) + 60); // 60-95% GPU load if (prev >= 100) { clearInterval(interval); setGpuLoad(0); setTimeout(() => { setIsConverting(false); setIsConverted(true); setShowNotification(true); setTimeout(() => setShowNotification(false), 4000); }, 300); return 100; } // accelerate progress conversion const step = Math.floor(Math.random() * 15) + 8; return Math.min(prev + step, 100); }); }, 150); }; const triggerScrollToFeatures = () => { const el = document.getElementById("features"); if (el) { window.scrollTo({ top: el.offsetTop - 85, behavior: "smooth", }); } }; const handleCustomFileUpload = (e: ChangeEvent) => { const file = e.target.files?.[0]; if (file) { const type = file.type.startsWith("image/") ? "image" : file.type.startsWith("video/") ? "video" : file.type.startsWith("audio/") ? "audio" : "document"; const mappedFile = { name: file.name, size: `${(file.size / (1024 * 1024)).toFixed(1)} MB`, type, }; setSelectedFile(mappedFile); setIsConverted(false); setProgress(0); setTargetFormat(CONVERSION_OPTIONS[type][0]); } }; const iconForType = (type: string) => { switch (type) { case "document": return ; case "image": return ; case "video": return