"use client" import { useState, useEffect } from "react" import { useRouter } from "next/navigation" import { Button } from "@/components/ui/button" import { Loader2, ArrowLeft, MapPin, Package, FolderKanban, RotateCcw, TrendingUp } from "lucide-react" import VideoPlayerSection from "@/components/video-player-section" import { SidebarNavigation } from "@/components/sidebar-navigation" import { PageHeader } from "@/components/page-header" import { type SessionContext, loadSession, loadVideoData, isSessionValid, clearSession } from "@/lib/api" import { getVideoFile, clearVideoFile } from "@/lib/video-storage" import { DetectionData, DetectionType } from "@/lib/types" const API_URL = process.env.NEXT_PUBLIC_API_URL import { ROUTES } from "@/utils/routes" export default function ResultsPage() { const router = useRouter() const [session, setSession] = useState(null) const [detectionData, setDetectionData] = useState(null) const [detectionType, setDetectionType] = useState("pothole-detection") const [videoId, setVideoId] = useState(null) const [videoFile, setVideoFile] = useState(null) const [isLoading, setIsLoading] = useState(true) const [error, setError] = useState(null) // Load session and video data on mount useEffect(() => { const storedSession = loadSession() const videoData = loadVideoData() if (!isSessionValid(storedSession) || !videoData) { router.replace(ROUTES.NEW_ANALYSIS) return } // If we have a videoId, redirect to the dynamic results page if (videoData.videoId) { router.replace(`${ROUTES.RESULTS}/${videoData.videoId}`) return } setSession(storedSession) }, [router]) const handleNewAnalysis = async () => { // Clear video from IndexedDB if (videoId) { try { await clearVideoFile(videoId) } catch (err) { console.error("Failed to clear video file:", err) } } clearSession() router.push(ROUTES.NEW_ANALYSIS) } const handleBackToUpload = () => { router.push(ROUTES.UPLOAD) } const getTitle = () => { if (detectionType === "pothole-detection") return "Pothole Detection Results" if (detectionType === "sign-board-detection") return "Signboard Detection Results" return "Pothole & Signboard Detection Results" } if (isLoading) { return (

Loading detection results...

) } if (error) { return (

{error}

) } return (
{/* Sidebar Navigation */} {/* Main Content */}
{/* Refined Header */}
{/* Session Info Bar */} {session && (
Project {session.projectName}
Package {session.packageName}
Location {session.locationName}
)} {/* Video Player Section */} {detectionData && videoId && (
)}
) }