import { VOCAB } from '../lib/collection-vocabulary.js'; const GAME_OPTIONS = [ { value: 'All', label: 'All games' }, { value: 'MTG', label: 'Magic' }, { value: 'Pokemon', label: 'Pokémon' }, { value: 'Lorcana', label: 'Lorcana' }, ]; function matchesGameFilter(itemGame, filter) { if (filter === 'All') return true; const normalized = (itemGame || '').toLowerCase(); if (filter === 'MTG') return normalized === 'mtg' || normalized.includes('magic'); if (filter === 'Pokemon') return normalized.includes('pokemon') || normalized.includes('pokémon'); if (filter === 'Lorcana') return normalized.includes('lorcana'); return itemGame === filter; } export default function ScannerDestinationPicker({ gameFilter, onGameFilterChange, destination, onDestinationChange, collections = [], decks = [], disabled = false, }) { const filteredCollections = collections.filter( (collection) => matchesGameFilter(collection.tcg, gameFilter) || collection.tcg === 'All' ); const filteredDecks = decks.filter((deck) => matchesGameFilter(deck.game, gameFilter)); const handleTypeChange = (type) => { if (type === 'owned') { onDestinationChange({ type: 'owned', id: null, label: VOCAB.MY_COLLECTION }); return; } if (type === 'collection' && filteredCollections.length > 0) { const first = filteredCollections[0]; onDestinationChange({ type: 'collection', id: first.id, label: first.name, }); return; } if (type === 'deck' && filteredDecks.length > 0) { const first = filteredDecks[0]; onDestinationChange({ type: 'deck', id: first.id, label: first.name, }); } }; const handleTargetChange = (event) => { const value = event.target.value; if (!value || !destination) return; if (destination.type === 'collection') { const collection = filteredCollections.find((item) => String(item.id) === value); if (collection) { onDestinationChange({ type: 'collection', id: collection.id, label: collection.name, }); } } if (destination.type === 'deck') { const deck = filteredDecks.find((item) => String(item.id) === value); if (deck) { onDestinationChange({ type: 'deck', id: deck.id, label: deck.name, }); } } }; return (

Scan destination

{destination ? `Every scan goes to: ${destination.label}` : 'Choose where scanned cards should land'}

Destination type {[ { type: 'owned', label: `💎 ${VOCAB.MY_COLLECTION}` }, { type: 'collection', label: `📚 ${VOCAB.LIST}` }, { type: 'deck', label: '🃏 Deck' }, ].map((option) => { const isActive = destination?.type === option.type; const isDisabled = (option.type === 'collection' && filteredCollections.length === 0) || (option.type === 'deck' && filteredDecks.length === 0); return ( ); })}
{destination?.type === 'collection' && filteredCollections.length > 0 && ( )} {destination?.type === 'deck' && filteredDecks.length > 0 && ( )} {destination?.type === 'collection' && filteredCollections.length === 0 && (

No lists match this game filter.

)} {destination?.type === 'deck' && filteredDecks.length === 0 && (

No decks match this game filter.

)}
); }