document.addEventListener('DOMContentLoaded', function() { // DOM Elements const cardSearch = document.getElementById('cardSearch'); const searchBtn = document.getElementById('searchBtn'); const cardResults = document.getElementById('cardResults'); const resultsSection = document.getElementById('resultsSection'); const deckSuggestions = document.getElementById('deckSuggestions'); const suggestionsList = document.getElementById('suggestionsList'); // Event Listeners searchBtn.addEventListener('click', searchCards); document.getElementById('searchByNameBtn').addEventListener('click', () => searchCards('name')); document.getElementById('searchByTypeBtn').addEventListener('click', () => searchCards('type')); document.getElementById('searchByColorBtn').addEventListener('click', () => searchCards('color')); // Mock data for demonstration const mockCards = [ { name: "Lightning Bolt", type: "Instant", color: "Red", image: "http://static.photos/red/320x240/1" }, { name: "Counterspell", type: "Instant", color: "Blue", image: "http://static.photos/blue/320x240/2" }, { name: "Llanowar Elves", type: "Creature", color: "Green", image: "http://static.photos/green/320x240/3" }, { name: "Swords to Plowshares", type: "Instant", color: "White", image: "http://static.photos/white/320x240/4" }, { name: "Dark Ritual", type: "Instant", color: "Black", image: "http://static.photos/black/320x240/5" }, { name: "Sol Ring", type: "Artifact", color: "Colorless", image: "http://static.photos/minimal/320x240/6" } ]; const mockDecks = [ { name: "Red Deck Wins", description: "Aggressive red deck with lots of direct damage", cards: ["Lightning Bolt", "Goblin Guide", "Monastery Swiftspear"] }, { name: "Blue Control", description: "Control the game with counterspells and card draw", cards: ["Counterspell", "Serum Visions", "Snapcaster Mage"] }, { name: "Green Ramp", description: "Ramp into big creatures quickly", cards: ["Llanowar Elves", "Cultivate", "Primeval Titan"] } ]; // Functions function searchCards(mode = 'name') { const searchTerm = cardSearch.value.trim(); if (!searchTerm) return; // Show loading state cardResults.innerHTML = '
'; resultsSection.classList.remove('hidden'); deckSuggestions.classList.add('hidden'); // Simulate API call with timeout setTimeout(() => { displayCards(mockCards); generateDeckSuggestions(); }, 1000); } function displayCards(cards) { cardResults.innerHTML = ''; if (cards.length === 0) { cardResults.innerHTML = '
No cards found in your collection
'; return; } cards.forEach(card => { const cardElement = document.createElement('div'); cardElement.className = 'card-item bg-white rounded-lg shadow-md overflow-hidden border border-gray-200'; cardElement.innerHTML = ` ${card.name}

${card.name}

${card.type}
`; cardResults.appendChild(cardElement); }); } function generateDeckSuggestions() { deckSuggestions.classList.remove('hidden'); suggestionsList.innerHTML = ''; mockDecks.forEach(deck => { const deckElement = document.createElement('div'); deckElement.className = 'deck-suggestion bg-gray-50 p-4 rounded-lg'; deckElement.innerHTML = `

${deck.name}

${deck.description}

${deck.cards.map(card => `${card}`).join('')}
`; suggestionsList.appendChild(deckElement); }); feather.replace(); } // Initialize feather icons feather.replace(); });