"use client" import { useState } from "react" import { UploadSection } from "@/components/upload-section" import VideoPlayerSection from "@/components/video-player-section" import { ProjectSelectionSection } from "@/components/project-selection-section" import { type SessionContext, emptySessionContext } from "@/lib/api" import { Button } from "@/components/ui/button" import { ArrowLeft, MapPin, Package, FolderKanban } from "lucide-react" export type DetectionType = "pothole-detection" | "sign-board-detection" export type DetectionData = { video_id: string detection_type?: string output_video_path?: string video_info: { fps: number width: number height: number total_frames: number } summary: { unique_potholes?: number unique_signboards?: number total_detections: number total_frames: number detection_rate: number } pothole_list?: Array<{ pothole_id: number first_detected_frame: number first_detected_time: number confidence: number lat?: number lng?: number }> signboard_list?: Array<{ signboard_id: number type: string first_detected_frame: number first_detected_time: number confidence: number lat?: number lng?: number }> frames: Array<{ frame_id: number potholes?: Array<{ pothole_id: number bbox: { x1: number y1: number x2: number y2: number } confidence: number }> signboards?: Array<{ signboard_id: number type: string bbox: { x1: number y1: number x2: number y2: number } confidence: number }> }> } export default function DetectionPage() { const [session, setSession] = useState(emptySessionContext) const [detectionData, setDetectionData] = useState(null) const [videoId, setVideoId] = useState(null) const [videoFile, setVideoFile] = useState(null) const [detectionType, setDetectionType] = useState("pothole-detection") const isSessionComplete = session.projectId && session.packageId && session.locationId const getTitle = () => { return detectionType === "pothole-detection" ? "Pothole Detection System" : "Signboard Detection System" } const getDescription = () => { return detectionType === "pothole-detection" ? "Upload a video to detect and track potholes with AI-powered analysis" : "Upload a video to detect and identify signboards with AI-powered analysis" } const handleSelectionComplete = (newSession: SessionContext) => { setSession(newSession) } const handleBackToSelection = () => { setSession(emptySessionContext) setDetectionData(null) setVideoId(null) setVideoFile(null) } return (
{/* Header */}

{isSessionComplete ? getTitle() : "VisionRoad Detection System"}

{isSessionComplete ? getDescription() : "Select your project location to begin AI-powered road analysis"}

{/* Session Info Bar */} {isSessionComplete && (
Project: {session.projectName}
Package: {session.packageName}
Location: {session.locationName}
)} {/* Project Selection Section - Show when session is not complete */} {!isSessionComplete && (
)} {/* Upload Section - Show after session is complete */} {isSessionComplete && (
{ setDetectionData(data) setVideoId(vId) setVideoFile(file) }} onDetectionTypeChange={setDetectionType} />
)} {/* Video Player Section */} {detectionData && videoId && videoFile && (
)}
) }