'use client';
import { useState } from 'react';
import { AlertTriangle, ImageIcon, Loader2 } from 'lucide-react';
import Image from 'next/image';
import { Dialog, DialogContent, DialogTitle } from '@/components/ui/dialog';
import { useProtectedMediaObjectUrl } from '@/hooks/useProtectedMedia';
import type { BoundingBoxOverlayItem, DetectionResultItem } from '@/types';
import BoundingBoxOverlay from '@/components/annotation/boundingBoxOverlay';
interface AnnotatedDetectionImageProps {
detection?: DetectionResultItem;
videoWidth: number;
videoHeight: number;
aspectRatio?: string;
enableLightbox?: boolean;
}
export default function AnnotatedDetectionImage({
detection,
videoWidth,
videoHeight,
aspectRatio: aspectRatioOverride,
enableLightbox = false,
}: AnnotatedDetectionImageProps) {
const [isPreviewOpen, setIsPreviewOpen] = useState(false);
const { objectUrl, isLoading, isError } = useProtectedMediaObjectUrl(
detection?.detection.context_image_url,
);
const overlayDetections: BoundingBoxOverlayItem[] = detection
? [
{
id: detection.id,
class_name: detection.detection.class_name,
display_name: detection.detection.display_name,
confidence: detection.detection.confidence,
bounding_box: detection.detection.bounding_box,
},
]
: [];
const aspectRatio =
aspectRatioOverride ??
(videoWidth > 0 && videoHeight > 0
? `${videoWidth} / ${videoHeight}`
: '16 / 9');
const annotatedMedia = objectUrl ? (
<>
Select a detection to view its image.
Loading detection image...
Failed to load the detection image.