import { useRef } from 'react';
import { useCameraScanner } from '../lib/use-camera-scanner.js';
import { useScannerIdentification } from '../lib/use-scanner-identification.js';
import ScanDisambiguationDialog from './ScanDisambiguationDialog.js';
export default function CameraScanner({ onCardScanned, onError }) {
const verificationPausedRef = useRef(false);
const onVerifyCardRef = useRef(() => {});
const {
videoRef,
canvasRef,
detectionCanvasRef,
isStreaming,
isDetecting,
trackedCards,
videoMetrics,
startCamera,
stopCamera,
} = useCameraScanner({
onError,
verificationPausedRef,
onVerifyCard: (card) => onVerifyCardRef.current(card),
});
const {
disambiguation,
scanNotice,
submittingReview,
handleDisambiguationPick,
handleNotInCatalog,
cancelDisambiguation,
} = useScannerIdentification({
onCardScanned,
onError,
videoRef,
canvasRef,
onVerifyCardRef,
verificationPausedRef,
});
const foundCardCount = trackedCards.filter(
(card) => card.status === 'confirmed' || card.status === 'scanned'
).length;
return (
{scanNotice && (
{scanNotice}
)}
{/* Camera Feed Container */}
{/* Video Element - Always rendered but visibility controlled */}
{/* Card Detection Overlays - Only when streaming */}
{isStreaming && videoMetrics.width > 0 && videoMetrics.height > 0 && trackedCards
.filter(card => card.status === 'confirmed' || card.status === 'scanned')
.map(card => (
{/* Status Label */}
{card.status === 'confirmed' ? '✅ Card Found' :
card.status === 'scanned' ? '📸 Scanned' :
'✅ Card Found'}
))}
{/* Top Status Bar - Only when streaming */}
{isStreaming && (
{/* Detection Status */}
{isDetecting && (
🎯 Scanning {foundCardCount > 0 && `(${foundCardCount} found)`}
)}
{/* Recording Indicator */}
)}
{/* Bottom Controls Overlay - Only when streaming */}
{isStreaming && (
)}
{/* Camera Placeholder with Centered Start Button - Only when not streaming */}
{!isStreaming && (
{/* Background Pattern */}
{/* Camera Icon and Content */}
Camera Ready
Position trading cards in view for smart detection
{/* Centered Start Camera Button */}
{/* Feature Hints */}
)}
{/* Hidden canvases for image processing */}
{/* Detection Info Panel - Only show when streaming */}
{isStreaming && (
●
Shape recognition
●
Server identification
●
Position tracking
●
Database lookup
)}
);
}