2026-06-02 16:44:56 -04:00
|
|
|
import { useEffect, useRef, useState } from 'react';
|
2026-06-02 12:01:32 -04:00
|
|
|
import { rateLimitCooldownUntil, uploadScanCapture } from '../lib/scan-capture-upload.js';
|
2026-06-02 16:34:13 -04:00
|
|
|
import {
|
|
|
|
|
buildScannedCardPayload,
|
|
|
|
|
getScanAuthHeaders,
|
|
|
|
|
identifyTrackedCardCapture,
|
|
|
|
|
resolveDisambiguationRefineAction,
|
|
|
|
|
submitScanForReview,
|
|
|
|
|
VISION_RATE_LIMIT_MS,
|
|
|
|
|
fetchVisionIdentify,
|
|
|
|
|
} from '../lib/scanner-card-identify.js';
|
2026-06-02 16:44:56 -04:00
|
|
|
import { useCameraScanner } from '../lib/use-camera-scanner.js';
|
2026-06-02 12:01:32 -04:00
|
|
|
import ScanDisambiguationDialog from './ScanDisambiguationDialog.js';
|
2026-05-27 14:57:26 -04:00
|
|
|
|
2025-07-29 15:19:48 -04:00
|
|
|
export default function CameraScanner({ onCardScanned, onError }) {
|
2026-05-27 09:47:05 -04:00
|
|
|
const [disambiguation, setDisambiguation] = useState(null);
|
2026-05-27 14:42:51 -04:00
|
|
|
const [scanNotice, setScanNotice] = useState(null);
|
|
|
|
|
const [submittingReview, setSubmittingReview] = useState(false);
|
2025-07-29 15:19:48 -04:00
|
|
|
|
2026-05-27 14:10:46 -04:00
|
|
|
const visionCooldownUntilRef = useRef(0);
|
|
|
|
|
const activeVerificationRef = useRef(0);
|
|
|
|
|
const lastErrorAtRef = useRef(0);
|
2026-05-27 14:42:51 -04:00
|
|
|
const disambiguationRefineRef = useRef(null);
|
2026-06-02 16:44:56 -04:00
|
|
|
const verificationPausedRef = useRef(false);
|
|
|
|
|
const onVerifyCardRef = useRef(() => {});
|
2025-07-29 15:19:48 -04:00
|
|
|
|
|
|
|
|
useEffect(() => {
|
2026-06-02 16:44:56 -04:00
|
|
|
verificationPausedRef.current = Boolean(disambiguation);
|
|
|
|
|
}, [disambiguation]);
|
|
|
|
|
|
|
|
|
|
const {
|
|
|
|
|
videoRef,
|
|
|
|
|
canvasRef,
|
|
|
|
|
detectionCanvasRef,
|
|
|
|
|
isStreaming,
|
|
|
|
|
isDetecting,
|
|
|
|
|
trackedCards,
|
|
|
|
|
videoMetrics,
|
|
|
|
|
startCamera,
|
|
|
|
|
stopCamera,
|
|
|
|
|
} = useCameraScanner({
|
|
|
|
|
onError,
|
|
|
|
|
verificationPausedRef,
|
|
|
|
|
onVerifyCard: (card) => onVerifyCardRef.current(card),
|
|
|
|
|
});
|
2025-07-29 15:19:48 -04:00
|
|
|
|
2026-05-27 14:57:26 -04:00
|
|
|
const emitScannedCard = async (cardTracker, imageData, finalCard, ocrMeta = {}) => {
|
2026-05-27 09:47:05 -04:00
|
|
|
cardTracker.status = 'scanned';
|
|
|
|
|
|
|
|
|
|
const originalTitle = document.title;
|
|
|
|
|
document.title = `📸 ${finalCard.name} - Card Scanner`;
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
document.title = originalTitle;
|
|
|
|
|
}, 3000);
|
|
|
|
|
|
2026-05-27 14:57:26 -04:00
|
|
|
let scanImageUrl = null;
|
|
|
|
|
if (imageData) {
|
|
|
|
|
try {
|
|
|
|
|
scanImageUrl = await uploadScanCapture(imageData);
|
|
|
|
|
} catch (uploadError) {
|
|
|
|
|
console.warn('Scan image upload failed:', uploadError);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-02 16:34:13 -04:00
|
|
|
onCardScanned(buildScannedCardPayload(finalCard, { imageData, scanImageUrl, ocrMeta }));
|
2026-05-27 09:47:05 -04:00
|
|
|
};
|
|
|
|
|
|
2026-05-27 14:57:26 -04:00
|
|
|
const handleDisambiguationPick = async (candidate) => {
|
2026-05-27 09:47:05 -04:00
|
|
|
if (!disambiguation) return;
|
|
|
|
|
const { cardTracker, imageData, ocrMeta } = disambiguation;
|
2026-05-27 14:57:26 -04:00
|
|
|
await emitScannedCard(cardTracker, imageData, candidate, ocrMeta);
|
2026-05-27 09:47:05 -04:00
|
|
|
setDisambiguation(null);
|
2026-05-27 14:42:51 -04:00
|
|
|
disambiguationRefineRef.current = null;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const showScanNotice = (message) => {
|
|
|
|
|
setScanNotice(message);
|
|
|
|
|
setTimeout(() => setScanNotice(null), 8000);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleReviewSubmitted = (cardTracker, message) => {
|
|
|
|
|
if (cardTracker) cardTracker.status = 'confirmed';
|
|
|
|
|
setDisambiguation(null);
|
|
|
|
|
disambiguationRefineRef.current = null;
|
|
|
|
|
showScanNotice(message);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleNotInCatalog = async () => {
|
|
|
|
|
if (!disambiguation || submittingReview) return;
|
|
|
|
|
setSubmittingReview(true);
|
|
|
|
|
|
|
|
|
|
const { cardTracker, imageData, candidates, ocrMeta } = disambiguation;
|
|
|
|
|
const guessedName =
|
|
|
|
|
ocrMeta?.cardName ||
|
|
|
|
|
ocrMeta?.query ||
|
|
|
|
|
candidates?.[0]?.name ||
|
|
|
|
|
null;
|
|
|
|
|
|
|
|
|
|
try {
|
2026-06-02 16:34:13 -04:00
|
|
|
const result = await submitScanForReview({
|
|
|
|
|
imageData,
|
|
|
|
|
name: guessedName,
|
|
|
|
|
candidateCardIds: (candidates || []).map((c) => c.id),
|
|
|
|
|
authHeaders: getScanAuthHeaders(),
|
2026-05-27 14:42:51 -04:00
|
|
|
});
|
|
|
|
|
|
2026-06-02 16:34:13 -04:00
|
|
|
if (result.rateLimited) {
|
|
|
|
|
visionCooldownUntilRef.current = rateLimitCooldownUntil(VISION_RATE_LIMIT_MS);
|
2026-05-27 14:42:51 -04:00
|
|
|
reportScannerError('Too many scan attempts. Please wait a moment and try again.');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
handleReviewSubmitted(cardTracker, result.message);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
reportScannerError(error.message || 'Failed to submit scan for review');
|
|
|
|
|
} finally {
|
|
|
|
|
setSubmittingReview(false);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2026-06-02 16:34:13 -04:00
|
|
|
const applyIdentifyOutcome = async (cardTracker, imageData, outcome) => {
|
|
|
|
|
cardTracker.status = outcome.cardStatus;
|
2026-05-27 14:42:51 -04:00
|
|
|
|
2026-06-02 16:34:13 -04:00
|
|
|
switch (outcome.type) {
|
|
|
|
|
case 'emit':
|
|
|
|
|
await emitScannedCard(cardTracker, imageData, outcome.card, outcome.ocrMeta);
|
|
|
|
|
break;
|
|
|
|
|
case 'disambiguation':
|
|
|
|
|
setDisambiguation({
|
|
|
|
|
cardTracker,
|
|
|
|
|
imageData,
|
|
|
|
|
candidates: outcome.matches,
|
|
|
|
|
ocrMeta: outcome.ocrMeta,
|
|
|
|
|
message: outcome.message,
|
|
|
|
|
});
|
|
|
|
|
break;
|
|
|
|
|
case 'notice':
|
|
|
|
|
showScanNotice(outcome.message);
|
|
|
|
|
break;
|
|
|
|
|
case 'error':
|
|
|
|
|
reportScannerError(outcome.message);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
2026-05-27 09:47:05 -04:00
|
|
|
}
|
2026-05-27 14:10:46 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const reportScannerError = (message) => {
|
2026-05-27 14:42:51 -04:00
|
|
|
if (disambiguation) return;
|
2026-05-27 14:10:46 -04:00
|
|
|
const now = Date.now();
|
|
|
|
|
if (now - lastErrorAtRef.current < 4000) return;
|
|
|
|
|
lastErrorAtRef.current = now;
|
|
|
|
|
onError?.(message);
|
2026-05-27 09:47:05 -04:00
|
|
|
};
|
|
|
|
|
|
2026-05-27 14:42:51 -04:00
|
|
|
useEffect(() => {
|
|
|
|
|
if (!disambiguation?.imageData) return;
|
|
|
|
|
if (Date.now() < visionCooldownUntilRef.current) return;
|
|
|
|
|
|
|
|
|
|
const refineKey = disambiguation.cardTracker?.id ?? 'modal';
|
|
|
|
|
if (disambiguationRefineRef.current === refineKey) return;
|
|
|
|
|
disambiguationRefineRef.current = refineKey;
|
|
|
|
|
|
|
|
|
|
let cancelled = false;
|
|
|
|
|
|
|
|
|
|
(async () => {
|
|
|
|
|
try {
|
2026-06-02 16:34:13 -04:00
|
|
|
const authHeaders = getScanAuthHeaders();
|
|
|
|
|
const vision = await fetchVisionIdentify(disambiguation.imageData, authHeaders);
|
2026-05-27 14:42:51 -04:00
|
|
|
if (cancelled) return;
|
|
|
|
|
|
2026-06-02 16:34:13 -04:00
|
|
|
if (vision.rateLimited) {
|
|
|
|
|
visionCooldownUntilRef.current = Date.now() + VISION_RATE_LIMIT_MS;
|
2026-05-27 14:42:51 -04:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-02 16:34:13 -04:00
|
|
|
const action = resolveDisambiguationRefineAction(vision.result, {
|
|
|
|
|
candidates: disambiguation.candidates,
|
|
|
|
|
});
|
2026-05-27 14:42:51 -04:00
|
|
|
if (cancelled) return;
|
|
|
|
|
|
2026-06-02 16:34:13 -04:00
|
|
|
switch (action.type) {
|
|
|
|
|
case 'review_submitted':
|
|
|
|
|
handleReviewSubmitted(disambiguation.cardTracker, action.message);
|
|
|
|
|
break;
|
|
|
|
|
case 'emit':
|
|
|
|
|
await emitScannedCard(
|
|
|
|
|
disambiguation.cardTracker,
|
|
|
|
|
disambiguation.imageData,
|
|
|
|
|
action.card,
|
|
|
|
|
action.ocrMeta
|
|
|
|
|
);
|
|
|
|
|
setDisambiguation(null);
|
|
|
|
|
disambiguationRefineRef.current = null;
|
|
|
|
|
break;
|
|
|
|
|
case 'pick':
|
|
|
|
|
await handleDisambiguationPick(action.candidate);
|
|
|
|
|
break;
|
|
|
|
|
case 'catalog_gap':
|
2026-05-27 14:42:51 -04:00
|
|
|
try {
|
2026-06-02 16:34:13 -04:00
|
|
|
const submitResult = await submitScanForReview({
|
|
|
|
|
imageData: disambiguation.imageData,
|
|
|
|
|
...action.submitPayload,
|
|
|
|
|
authHeaders,
|
2026-05-27 14:42:51 -04:00
|
|
|
});
|
2026-06-02 16:34:13 -04:00
|
|
|
if (submitResult.ok) {
|
2026-05-27 14:42:51 -04:00
|
|
|
handleReviewSubmitted(disambiguation.cardTracker, submitResult.message);
|
|
|
|
|
}
|
|
|
|
|
} catch {
|
|
|
|
|
setDisambiguation((current) =>
|
|
|
|
|
current
|
|
|
|
|
? {
|
|
|
|
|
...current,
|
2026-06-02 16:34:13 -04:00
|
|
|
visionHint: action.setHint,
|
|
|
|
|
message: action.hintMessage,
|
2026-05-27 14:42:51 -04:00
|
|
|
}
|
|
|
|
|
: current
|
|
|
|
|
);
|
|
|
|
|
}
|
2026-06-02 16:34:13 -04:00
|
|
|
break;
|
|
|
|
|
case 'narrow':
|
2026-05-27 14:42:51 -04:00
|
|
|
setDisambiguation((current) =>
|
|
|
|
|
current
|
|
|
|
|
? {
|
|
|
|
|
...current,
|
2026-06-02 16:34:13 -04:00
|
|
|
candidates: action.filtered,
|
|
|
|
|
message: action.message,
|
|
|
|
|
visionHint: action.visionHint,
|
2026-05-27 14:42:51 -04:00
|
|
|
}
|
|
|
|
|
: current
|
|
|
|
|
);
|
2026-06-02 16:34:13 -04:00
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
2026-05-27 14:42:51 -04:00
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.warn('Disambiguation vision refine failed:', error);
|
|
|
|
|
}
|
|
|
|
|
})();
|
|
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
|
cancelled = true;
|
|
|
|
|
};
|
2026-06-02 02:03:36 -04:00
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps -- refine runs per disambiguation session, not per handler identity
|
2026-05-27 14:42:51 -04:00
|
|
|
}, [disambiguation?.cardTracker?.id, disambiguation?.imageData]);
|
|
|
|
|
|
2025-08-01 18:41:42 -04:00
|
|
|
const verifyCardShape = async (cardTracker) => {
|
|
|
|
|
if (!videoRef.current || !canvasRef.current || cardTracker.status !== 'detecting') return;
|
2026-05-27 14:10:46 -04:00
|
|
|
if (disambiguation) return;
|
|
|
|
|
if (activeVerificationRef.current >= 1) return;
|
|
|
|
|
|
|
|
|
|
activeVerificationRef.current += 1;
|
|
|
|
|
cardTracker.status = 'verifying';
|
2026-05-27 09:47:05 -04:00
|
|
|
|
2025-07-29 15:19:48 -04:00
|
|
|
try {
|
2025-08-01 18:41:42 -04:00
|
|
|
cardTracker.scanAttempts++;
|
2026-05-27 09:47:05 -04:00
|
|
|
|
2026-06-02 16:34:13 -04:00
|
|
|
const identification = await identifyTrackedCardCapture({
|
|
|
|
|
video: videoRef.current,
|
|
|
|
|
canvas: canvasRef.current,
|
|
|
|
|
cardTracker,
|
|
|
|
|
authHeaders: getScanAuthHeaders(),
|
|
|
|
|
visionCooldownUntilMs: visionCooldownUntilRef.current,
|
|
|
|
|
});
|
2026-05-27 13:59:59 -04:00
|
|
|
|
2026-06-02 16:34:13 -04:00
|
|
|
if (identification.retry) {
|
2026-05-27 14:10:46 -04:00
|
|
|
cardTracker.status = 'detecting';
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-02 16:34:13 -04:00
|
|
|
if (identification.rateLimited) {
|
|
|
|
|
visionCooldownUntilRef.current = Date.now() + VISION_RATE_LIMIT_MS;
|
2026-05-27 14:10:46 -04:00
|
|
|
reportScannerError('Too many scan attempts. Please wait a moment and try again.');
|
2026-05-27 09:47:05 -04:00
|
|
|
cardTracker.status = 'negative';
|
|
|
|
|
return;
|
2025-07-29 15:19:48 -04:00
|
|
|
}
|
|
|
|
|
|
2026-06-02 16:34:13 -04:00
|
|
|
if (identification.handled && identification.outcome) {
|
|
|
|
|
cardTracker.status = 'confirmed';
|
|
|
|
|
await applyIdentifyOutcome(cardTracker, identification.imageData, identification.outcome);
|
2025-07-29 15:19:48 -04:00
|
|
|
}
|
2025-08-01 18:41:42 -04:00
|
|
|
} catch (error) {
|
2026-05-27 09:47:05 -04:00
|
|
|
console.error(`Error verifying card ${cardTracker.id}:`, error);
|
2025-08-01 18:41:42 -04:00
|
|
|
cardTracker.status = 'negative';
|
2026-05-27 14:10:46 -04:00
|
|
|
reportScannerError(error.message || 'Scan failed');
|
|
|
|
|
} finally {
|
|
|
|
|
activeVerificationRef.current = Math.max(0, activeVerificationRef.current - 1);
|
2025-08-01 18:41:42 -04:00
|
|
|
}
|
|
|
|
|
};
|
2025-07-29 15:19:48 -04:00
|
|
|
|
2026-06-02 02:03:36 -04:00
|
|
|
useEffect(() => {
|
2026-06-02 16:44:56 -04:00
|
|
|
onVerifyCardRef.current = verifyCardShape;
|
|
|
|
|
});
|
2026-06-02 02:03:36 -04:00
|
|
|
|
2026-06-02 16:44:56 -04:00
|
|
|
const foundCardCount = trackedCards.filter(
|
|
|
|
|
(card) => card.status === 'confirmed' || card.status === 'scanned'
|
|
|
|
|
).length;
|
2025-07-29 15:19:48 -04:00
|
|
|
|
|
|
|
|
return (
|
2025-08-01 18:41:42 -04:00
|
|
|
<div className="w-full h-full flex flex-col">
|
2026-05-27 14:42:51 -04:00
|
|
|
{scanNotice && (
|
|
|
|
|
<div
|
|
|
|
|
className="mx-4 mt-3 px-4 py-3 rounded-lg text-sm border"
|
|
|
|
|
style={{
|
|
|
|
|
backgroundColor: 'var(--bg-secondary)',
|
|
|
|
|
borderColor: 'var(--accent-ember)',
|
|
|
|
|
color: 'var(--text-primary)',
|
|
|
|
|
}}
|
|
|
|
|
role="status"
|
|
|
|
|
>
|
|
|
|
|
{scanNotice}
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
2025-08-01 18:41:42 -04:00
|
|
|
{/* Camera Feed Container */}
|
2025-07-29 15:19:48 -04:00
|
|
|
<div
|
2025-08-01 18:41:42 -04:00
|
|
|
className="flex-1 relative rounded-2xl overflow-hidden mb-4"
|
2025-07-29 15:19:48 -04:00
|
|
|
style={{
|
2025-08-01 18:41:42 -04:00
|
|
|
backgroundColor: 'var(--bg-tertiary)',
|
|
|
|
|
border: '2px solid var(--border)'
|
2025-07-29 15:19:48 -04:00
|
|
|
}}
|
|
|
|
|
>
|
2025-08-01 18:41:42 -04:00
|
|
|
{/* Video Element - Always rendered but visibility controlled */}
|
2025-07-29 15:19:48 -04:00
|
|
|
<video
|
|
|
|
|
ref={videoRef}
|
2025-08-01 18:41:42 -04:00
|
|
|
className={`absolute inset-0 w-full h-full object-cover ${isStreaming ? 'block' : 'hidden'}`}
|
2025-07-29 15:19:48 -04:00
|
|
|
autoPlay
|
|
|
|
|
playsInline
|
|
|
|
|
muted
|
2026-05-27 15:22:18 -04:00
|
|
|
aria-label="Card scanner camera feed"
|
2025-07-29 15:19:48 -04:00
|
|
|
/>
|
2025-08-01 18:41:42 -04:00
|
|
|
|
|
|
|
|
{/* Card Detection Overlays - Only when streaming */}
|
2026-06-02 02:03:36 -04:00
|
|
|
{isStreaming && videoMetrics.width > 0 && videoMetrics.height > 0 && trackedCards
|
2025-08-01 18:41:42 -04:00
|
|
|
.filter(card => card.status === 'confirmed' || card.status === 'scanned')
|
|
|
|
|
.map(card => (
|
|
|
|
|
<div
|
|
|
|
|
key={card.id}
|
|
|
|
|
className="absolute border-2 rounded-lg transition-all duration-200"
|
|
|
|
|
style={{
|
2026-06-02 02:03:36 -04:00
|
|
|
left: `${(card.bounds.x / videoMetrics.width) * 100}%`,
|
|
|
|
|
top: `${(card.bounds.y / videoMetrics.height) * 100}%`,
|
|
|
|
|
width: `${(card.bounds.width / videoMetrics.width) * 100}%`,
|
|
|
|
|
height: `${(card.bounds.height / videoMetrics.height) * 100}%`,
|
2025-08-01 18:41:42 -04:00
|
|
|
borderColor:
|
|
|
|
|
card.status === 'confirmed' ? '#10B981' : // Green for confirmed
|
|
|
|
|
card.status === 'scanned' ? '#3B82F6' : // Blue for scanned
|
|
|
|
|
'#10B981', // Default to green
|
|
|
|
|
borderWidth: '3px',
|
|
|
|
|
boxShadow: `0 0 15px ${
|
|
|
|
|
card.status === 'confirmed' ? '#10B98150' :
|
|
|
|
|
card.status === 'scanned' ? '#3B82F650' :
|
|
|
|
|
'#10B98150'
|
|
|
|
|
}`
|
2025-07-29 15:19:48 -04:00
|
|
|
}}
|
|
|
|
|
>
|
2025-08-01 18:41:42 -04:00
|
|
|
{/* Status Label */}
|
2025-07-29 15:19:48 -04:00
|
|
|
<div
|
2025-08-01 18:41:42 -04:00
|
|
|
className="absolute -top-8 left-0 px-3 py-1 rounded-full text-xs font-bold text-white shadow-lg"
|
|
|
|
|
style={{
|
|
|
|
|
backgroundColor:
|
|
|
|
|
card.status === 'confirmed' ? '#10B981' :
|
|
|
|
|
card.status === 'scanned' ? '#3B82F6' :
|
|
|
|
|
'#10B981'
|
2025-07-29 15:19:48 -04:00
|
|
|
}}
|
|
|
|
|
>
|
2025-08-01 18:41:42 -04:00
|
|
|
{card.status === 'confirmed' ? '✅ Card Found' :
|
|
|
|
|
card.status === 'scanned' ? '📸 Scanned' :
|
|
|
|
|
'✅ Card Found'}
|
2025-07-29 15:19:48 -04:00
|
|
|
</div>
|
|
|
|
|
</div>
|
2025-08-01 18:41:42 -04:00
|
|
|
))}
|
2025-07-29 15:19:48 -04:00
|
|
|
|
2025-08-01 18:41:42 -04:00
|
|
|
{/* Top Status Bar - Only when streaming */}
|
2025-07-29 15:19:48 -04:00
|
|
|
{isStreaming && (
|
2025-08-01 18:41:42 -04:00
|
|
|
<div className="absolute top-4 left-4 right-4 flex justify-between items-center">
|
|
|
|
|
{/* Detection Status */}
|
|
|
|
|
{isDetecting && (
|
|
|
|
|
<div className="bg-black bg-opacity-80 text-white px-4 py-2 rounded-full text-sm font-medium shadow-lg backdrop-blur-sm">
|
|
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
|
<div className="w-2 h-2 bg-green-400 rounded-full animate-pulse"></div>
|
2026-06-02 16:44:56 -04:00
|
|
|
🎯 Scanning {foundCardCount > 0 && `(${foundCardCount} found)`}
|
2025-07-29 15:19:48 -04:00
|
|
|
</div>
|
2025-08-01 18:41:42 -04:00
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
<div className="flex-1"></div>
|
|
|
|
|
|
|
|
|
|
{/* Recording Indicator */}
|
|
|
|
|
<div className="bg-black bg-opacity-80 text-white px-4 py-2 rounded-full text-sm font-medium shadow-lg backdrop-blur-sm">
|
|
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
|
<div className="w-2 h-2 bg-red-500 rounded-full animate-pulse"></div>
|
|
|
|
|
LIVE
|
2025-07-29 15:19:48 -04:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
2025-08-01 18:41:42 -04:00
|
|
|
|
|
|
|
|
{/* Bottom Controls Overlay - Only when streaming */}
|
|
|
|
|
{isStreaming && (
|
|
|
|
|
<div className="absolute bottom-6 left-1/2 transform -translate-x-1/2">
|
|
|
|
|
<div className="flex items-center gap-4">
|
|
|
|
|
{/* Stop Button */}
|
|
|
|
|
<button
|
|
|
|
|
onClick={stopCamera}
|
|
|
|
|
className="w-16 h-16 rounded-full flex items-center justify-center text-white shadow-2xl hover:scale-105 transition-all duration-200 backdrop-blur-sm"
|
|
|
|
|
style={{
|
|
|
|
|
backgroundColor: 'rgba(239, 68, 68, 0.9)',
|
|
|
|
|
border: '3px solid rgba(255, 255, 255, 0.3)'
|
|
|
|
|
}}
|
2026-05-27 15:22:18 -04:00
|
|
|
aria-label="Stop camera"
|
2025-08-01 18:41:42 -04:00
|
|
|
>
|
2026-05-27 15:22:18 -04:00
|
|
|
<div className="w-6 h-6 bg-white rounded-sm" aria-hidden="true"></div>
|
2025-08-01 18:41:42 -04:00
|
|
|
</button>
|
2025-07-29 15:19:48 -04:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
|
2025-08-01 18:41:42 -04:00
|
|
|
{/* Camera Placeholder with Centered Start Button - Only when not streaming */}
|
|
|
|
|
{!isStreaming && (
|
|
|
|
|
<div className="absolute inset-0 flex flex-col items-center justify-center">
|
|
|
|
|
{/* Background Pattern */}
|
|
|
|
|
<div className="absolute inset-0 opacity-5">
|
|
|
|
|
<div className="w-full h-full" style={{
|
|
|
|
|
backgroundImage: `radial-gradient(circle at 25% 25%, var(--text-primary) 2px, transparent 2px),
|
|
|
|
|
radial-gradient(circle at 75% 75%, var(--text-primary) 2px, transparent 2px)`,
|
|
|
|
|
backgroundSize: '50px 50px'
|
|
|
|
|
}}></div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* Camera Icon and Content */}
|
|
|
|
|
<div className="text-center z-10 mb-8">
|
|
|
|
|
<div className="font-semibold text-2xl mb-3" style={{ color: 'var(--text-primary)' }}>
|
|
|
|
|
Camera Ready
|
|
|
|
|
</div>
|
|
|
|
|
<div className="text-lg opacity-75 mb-6" style={{ color: 'var(--text-secondary)' }}>
|
|
|
|
|
Position trading cards in view for smart detection
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* Centered Start Camera Button */}
|
|
|
|
|
<button
|
|
|
|
|
onClick={startCamera}
|
|
|
|
|
className="w-20 h-20 rounded-full flex items-center justify-center text-white shadow-2xl hover:scale-110 transition-all duration-300 relative overflow-hidden group"
|
|
|
|
|
style={{
|
|
|
|
|
backgroundColor: 'var(--accent-ember)',
|
|
|
|
|
border: '4px solid rgba(255, 255, 255, 0.2)'
|
|
|
|
|
}}
|
2026-05-27 15:22:18 -04:00
|
|
|
aria-label="Start camera"
|
2025-08-01 18:41:42 -04:00
|
|
|
>
|
|
|
|
|
{/* Button Glow Effect */}
|
|
|
|
|
<div className="absolute inset-0 rounded-full opacity-0 group-hover:opacity-100 transition-opacity duration-300"
|
|
|
|
|
style={{
|
|
|
|
|
background: `radial-gradient(circle, rgba(255,255,255,0.3) 0%, transparent 70%)`
|
|
|
|
|
}}></div>
|
|
|
|
|
|
|
|
|
|
{/* Play Icon */}
|
2026-05-27 15:22:18 -04:00
|
|
|
<div className="relative z-10" aria-hidden="true">
|
2025-08-01 18:41:42 -04:00
|
|
|
<svg width="28" height="28" viewBox="0 0 24 24" fill="currentColor">
|
|
|
|
|
<path d="M8 5v14l11-7z"/>
|
|
|
|
|
</svg>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* Pulse Ring */}
|
|
|
|
|
<div className="absolute inset-0 rounded-full border-2 border-white opacity-60 animate-ping"></div>
|
|
|
|
|
</button>
|
|
|
|
|
|
|
|
|
|
{/* Feature Hints */}
|
|
|
|
|
<div className="mt-8 text-center max-w-md">
|
|
|
|
|
<div className="grid grid-cols-2 gap-4 text-sm" style={{ color: 'var(--text-secondary)' }}>
|
|
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
|
<div className="w-2 h-2 rounded-full" style={{ backgroundColor: 'var(--accent-gold)' }}></div>
|
|
|
|
|
<span>AI Detection</span>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
|
<div className="w-2 h-2 rounded-full" style={{ backgroundColor: 'var(--accent-ember)' }}></div>
|
|
|
|
|
<span>Real-time Tracking</span>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
|
<div className="w-2 h-2 rounded-full" style={{ backgroundColor: 'var(--accent-flame)' }}></div>
|
|
|
|
|
<span>Smart Recognition</span>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
|
<div className="w-2 h-2 rounded-full bg-green-500"></div>
|
|
|
|
|
<span>Auto Scanning</span>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
2025-07-29 15:19:48 -04:00
|
|
|
</div>
|
2025-08-01 18:41:42 -04:00
|
|
|
)}
|
|
|
|
|
</div>
|
2025-07-29 15:19:48 -04:00
|
|
|
|
|
|
|
|
{/* Hidden canvases for image processing */}
|
|
|
|
|
<canvas ref={canvasRef} className="hidden" />
|
|
|
|
|
<canvas ref={detectionCanvasRef} className="hidden" />
|
|
|
|
|
|
2025-08-01 18:41:42 -04:00
|
|
|
{/* Detection Info Panel - Only show when streaming */}
|
|
|
|
|
{isStreaming && (
|
|
|
|
|
<div className="rounded-xl p-3 border" style={{ backgroundColor: 'var(--bg-secondary)', borderColor: 'var(--border)' }}>
|
|
|
|
|
<div className="flex items-center gap-3 mb-2">
|
|
|
|
|
<div className="w-6 h-6 rounded-full flex items-center justify-center" style={{ backgroundColor: 'var(--accent-ember)' }}>
|
|
|
|
|
<span className="text-white text-xs">🎯</span>
|
2025-07-29 15:19:48 -04:00
|
|
|
</div>
|
2026-05-27 15:22:18 -04:00
|
|
|
<h3 className="font-medium text-sm" style={{ color: 'var(--text-primary)' }}>
|
2025-08-01 18:41:42 -04:00
|
|
|
Smart Detection Active
|
2026-05-27 15:22:18 -04:00
|
|
|
</h3>
|
2025-07-29 15:19:48 -04:00
|
|
|
</div>
|
2025-08-01 18:41:42 -04:00
|
|
|
<div className="grid grid-cols-2 gap-2 text-xs" style={{ color: 'var(--text-secondary)' }}>
|
|
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
|
<span className="text-green-500">●</span>
|
|
|
|
|
<span>Shape recognition</span>
|
2025-07-29 15:19:48 -04:00
|
|
|
</div>
|
2025-08-01 18:41:42 -04:00
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
|
<span className="text-blue-500">●</span>
|
2026-05-27 09:47:05 -04:00
|
|
|
<span>Server identification</span>
|
2025-07-29 15:19:48 -04:00
|
|
|
</div>
|
2025-08-01 18:41:42 -04:00
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
|
<span className="text-yellow-500">●</span>
|
|
|
|
|
<span>Position tracking</span>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="flex items-center gap-2">
|
|
|
|
|
<span className="text-purple-500">●</span>
|
|
|
|
|
<span>Database lookup</span>
|
2025-07-29 15:19:48 -04:00
|
|
|
</div>
|
2025-08-01 18:41:42 -04:00
|
|
|
</div>
|
2025-07-29 15:19:48 -04:00
|
|
|
</div>
|
|
|
|
|
)}
|
2026-05-27 09:47:05 -04:00
|
|
|
|
2026-06-02 12:01:32 -04:00
|
|
|
<ScanDisambiguationDialog
|
|
|
|
|
disambiguation={disambiguation}
|
|
|
|
|
submittingReview={submittingReview}
|
|
|
|
|
onPick={handleDisambiguationPick}
|
|
|
|
|
onNotInCatalog={handleNotInCatalog}
|
|
|
|
|
onCancel={() => {
|
|
|
|
|
setDisambiguation(null);
|
|
|
|
|
disambiguationRefineRef.current = null;
|
|
|
|
|
}}
|
|
|
|
|
/>
|
2025-07-29 15:19:48 -04:00
|
|
|
</div>
|
|
|
|
|
);
|
2026-06-02 16:34:13 -04:00
|
|
|
}
|