import { useState, useId } from 'react'; import { VOCAB, collectionDisplayName } from '../../lib/collection-vocabulary.js'; import { Button } from '../ui'; const GAMES = [ { value: 'All', label: 'Auto-detect' }, { value: 'mtg', label: 'Magic' }, { value: 'pokemon', label: 'Pokémon' }, { value: 'lorcana', label: 'Lorcana' }, ]; const DECK_SIZES = [ { value: 40, label: '40' }, { value: 60, label: '60' }, { value: 99, label: '99' }, ]; const DESTINATION_TYPES = [ { value: 'owned', label: VOCAB.MY_COLLECTION }, { value: 'collection', label: VOCAB.LIST }, { value: 'deck', label: 'Deck' }, ]; function ToggleGroup({ options, value, onChange, name, className = '' }) { return (
{options.map((opt) => { const selected = opt.value === value; return ( ); })}
); } function ScanHistoryList({ history }) { const [expanded, setExpanded] = useState(false); const panelId = useId(); if (!history || history.length === 0) return null; const formatDate = (iso) => { try { return new Date(iso).toLocaleDateString(undefined, { month: 'short', day: 'numeric', hour: 'numeric', minute: '2-digit', }); } catch { return 'Unknown date'; } }; const destinationLabel = (dest) => { if (!dest) return 'Unknown'; if (dest.type === 'owned') return VOCAB.MY_COLLECTION; return dest.label || dest.type; }; return (
{expanded && ( )}
); } export default function ScannerSetup({ sessionDestination, onDestinationChange, gameFilter, onGameFilterChange, collections, decks, deckMode, onDeckModeChange, onStartScanning, scanHistory, }) { const destSelectId = useId(); const gameGroupId = useId(); const deckModeId = useId(); const deckSizeId = useId(); const destinationType = sessionDestination?.type ?? 'owned'; const handleDestinationTypeChange = (type) => { if (type === 'owned') { onDestinationChange({ type: 'owned', id: null, label: VOCAB.MY_COLLECTION }); } else if (type === 'collection') { const first = collections?.[0]; onDestinationChange( first ? { type: 'collection', id: first.id, label: collectionDisplayName(first) } : { type: 'collection', id: null, label: VOCAB.LIST } ); } else if (type === 'deck') { const first = decks?.[0]; onDestinationChange( first ? { type: 'deck', id: first.id, label: first.name } : { type: 'deck', id: null, label: 'Deck' } ); } }; const handleListSelect = (e) => { const id = parseInt(e.target.value, 10); const found = collections.find((c) => c.id === id); if (found) { onDestinationChange({ type: 'collection', id: found.id, label: collectionDisplayName(found), }); } }; const handleDeckSelect = (e) => { const id = parseInt(e.target.value, 10); const found = decks.find((d) => d.id === id); if (found) { onDestinationChange({ type: 'deck', id: found.id, label: found.name }); } }; const handleDeckModeToggle = () => { if (deckMode) { onDeckModeChange(null); } else { onDeckModeChange({ game: gameFilter, targetSize: 60 }); } }; const handleDeckSizeChange = (size) => { onDeckModeChange({ ...deckMode, targetSize: size }); }; const selectStyle = { backgroundColor: 'var(--bg-tertiary)', color: 'var(--text-primary)', borderColor: 'var(--border)', }; return (

Card Scanner

Choose where scanned cards will go

{/* Destination picker */}
Destination {destinationType === 'collection' && (
)} {destinationType === 'deck' && (
)}
{/* Game filter */}
Game
{/* Deck mode toggle */}
{deckMode && (
Deck Size
)} {/* Start scanning CTA */} {/* Scan history */}
); }