"use client"; import { useCallback, useState, useEffect } from "react"; import { useDropzone } from "react-dropzone"; import { useRouter } from "next/navigation"; import { motion, AnimatePresence } from "framer-motion"; import { colors, motionPresets } from "@/lib/tokens"; import { useGUCStore, type ParsedReport } from "@/lib/store"; import { getNextMock } from "@/lib/mockData"; const LOADING_STEPS = [ "रिपोर्ट पढ़ रहे हैं... (Reading report...)", "मेडिकल शब्द समझ रहे हैं... (Understanding jargon...)", "हिंदी में अनुवाद हो रहा है... (Translating to Hindi...)", "लगभग हो गया! (Almost done!)", ]; const FEATURES = [ { icon: "🔒", label: "100% Private" }, { icon: "⚡", label: "Instant Results" }, { icon: "🇮🇳", label: "Made for India" }, ]; export default function Home() { const router = useRouter(); const setLatestReport = useGUCStore((s) => s.setLatestReport); const language = useGUCStore((s) => s.profile.language); const [file, setFile] = useState(null); const [loading, setLoading] = useState(false); const [loadingStep, setLoadingStep] = useState(0); const [progress, setProgress] = useState(0); const [dots, setDots] = useState<{ x: number; y: number; size: number; opacity: number }[]>([]); const [error, setError] = useState(null); useEffect(() => { setDots(Array.from({ length: 50 }, () => ({ x: Math.random() * 100, y: Math.random() * 100, size: Math.random() * 2 + 0.5, opacity: Math.random() * 0.25 + 0.04, }))); }, []); useEffect(() => { if (!loading) return; const id = setInterval(() => setLoadingStep((s) => (s + 1) % LOADING_STEPS.length), 800); return () => clearInterval(id); }, [loading]); useEffect(() => { if (!loading) { setProgress(0); return; } const start = Date.now(); const total = 15000; // Match the API timeout const id = setInterval(() => { const elapsed = Date.now() - start; // Progress moves slower toward end to feel more natural const pct = Math.min((elapsed / total) * 85, 85); setProgress(pct); if (elapsed >= total) clearInterval(id); }, 50); return () => clearInterval(id); }, [loading]); const onDrop = useCallback((accepted: File[]) => { setFile(accepted[0]); setError(null); }, []); const { getRootProps, getInputProps, isDragActive } = useDropzone({ onDrop, accept: { "image/*": [], "application/pdf": [] }, maxFiles: 1, }); const handleAnalyze = async () => { if (!file) return; setError(null); setLoading(true); try { const formData = new FormData(); formData.append("file", file); formData.append("language", language); const res = await fetch("/api/analyze-report", { method: "POST", body: formData, }); const data = await res.json(); if (res.ok && data.is_readable !== undefined) { // Success — save to store setLatestReport(data as ParsedReport); setProgress(100); await new Promise((r) => setTimeout(r, 400)); router.push("/dashboard"); } else if (data.useMock || !res.ok) { // Backend failed or timed out — use mock data console.warn("Using mock fallback:", data.error); const mock = getNextMock(); setLatestReport(mock); setProgress(100); await new Promise((r) => setTimeout(r, 400)); router.push("/dashboard"); } } catch { // Network error — use mock data console.warn("Network error, using mock fallback"); const mock = getNextMock(); setLatestReport(mock); setProgress(100); await new Promise((r) => setTimeout(r, 400)); router.push("/dashboard"); } finally { setLoading(false); } }; return (
{/* Enhanced ambient glow */}
{/* Starfield */} {dots.map((dot, i) => (
))} {/* Loading overlay */} {loading && ( {/* Animated pipeline */} 📄 Report {[0, 1, 2].map((i) => ( ))} 🧠 AI Engine {LOADING_STEPS[loadingStep]} {/* Progress bar */}

{Math.round(progress)}%

)}
{/* Main card */} {/* Logo */}
🏥
Report

Raahat

अपनी मेडिकल रिपोर्ट समझें — आसान हिंदी में

Upload your report and understand it instantly

{/* Language toggle */}
{(["HI", "EN"] as const).map((lang) => ( ))}
{/* Drop zone */}
{file ? (

{file.name}

Ready! Click Samjho below ↓

) : ( 📋

{isDragActive ? "Drop it here! 🎯" : "Drag & drop your report"}

or click to browse — PDF or Image

Supports: JPG, PNG, PDF

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

{error}

)} {/* CTA button */} ✨ Samjho! — समझो {/* Feature chips */}
{FEATURES.map((f) => (
{f.icon} {f.label}
))}
{/* Floating chat pill */} 🤖 Dr. Raahat
); }