File size: 5,072 Bytes
c78e5bd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
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 = '<div class="col-span-3 text-center py-8"><div class="inline-block spinner border-4 border-red-500 border-t-transparent rounded-full w-12 h-12"></div></div>';
        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 = '<div class="col-span-3 text-center py-8 text-gray-500">No cards found in your collection</div>';
            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 = `
                <img src="${card.image}" alt="${card.name}" class="w-full h-48 object-cover">
                <div class="p-4">
                    <h3 class="font-bold text-lg text-gray-800">${card.name}</h3>
                    <div class="flex items-center mt-2">
                        <span class="inline-block w-3 h-3 rounded-full mr-2 bg-${card.color.toLowerCase()}-500"></span>
                        <span class="text-sm text-gray-600">${card.type}</span>
                    </div>
                </div>
            `;
            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 = `
                <h3 class="font-bold text-xl text-red-600 mb-2">${deck.name}</h3>
                <p class="text-gray-700 mb-3">${deck.description}</p>
                <div class="flex flex-wrap gap-2 mb-3">
                    ${deck.cards.map(card => `<span class="bg-orange-100 text-orange-800 px-2 py-1 rounded-full text-sm">${card}</span>`).join('')}
                </div>
                <button class="bg-red-500 hover:bg-red-600 text-white px-4 py-2 rounded-lg flex items-center">
                    <i data-feather="plus" class="mr-2"></i> Build This Deck
                </button>
            `;
            suggestionsList.appendChild(deckElement);
        });
        
        feather.replace();
    }
    
    // Initialize feather icons
    feather.replace();
});