'use client'; import { useState, useEffect } from 'react'; import { useRouter } from 'next/navigation'; import { Button } from '@/components/ui/button'; import { Loader2, TrendingUp } from 'lucide-react'; import VideoPlayerSection from '@/components/video-player-section'; import { PageHeader } from '@/components/page-header'; import { PoweredBy } from '@/components/powered-by'; import { sessionService } from '@/services/api'; import { SessionContext, DetectionData, DetectionType } from '@/types'; import { clearVideoFile } from '@/lib/video-storage'; import { ROUTES } from '@/utils/routes'; import { Card } from '@/components/ui/card'; export default function ResultsPage() { const router = useRouter(); const [session, setSession] = useState(null); const [detectionData] = useState(null); const [detectionType] = useState('pothole-detection'); const [videoId] = useState(null); const [videoFile] = useState(null); const [isLoading] = useState(true); const [error] = useState(null); // Load session and video data on mount useEffect(() => { const storedSession = sessionService.loadSession(); const videoData = sessionService.loadVideoData(); if (!sessionService.isSessionValid(storedSession) || !videoData) { router.replace(ROUTES.UPLOAD); 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); } } sessionService.clearSession(); 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 results...

); } if (error) { return (

{error}

); } return (
{session && (
Project {session.projectName}
Package {session.packageName}
Segment {session.chainageName}
)} {detectionData && videoId && ( )}
); }