File size: 6,519 Bytes
6775045
e284f77
6775045
e284f77
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6775045
 
e284f77
6775045
 
 
 
e284f77
 
6775045
e284f77
 
 
 
 
 
 
6775045
e284f77
 
 
 
 
 
 
 
 
 
6775045
e284f77
 
 
6775045
 
e284f77
6775045
e284f77
6775045
 
 
 
e284f77
6775045
e284f77
6775045
 
 
 
 
e284f77
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6775045
 
 
e284f77
6775045
 
e284f77
6775045
e284f77
 
6775045
 
e284f77
6775045
 
 
 
 
e284f77
6775045
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e284f77
 
 
6775045
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e284f77
 
 
 
 
 
6775045
 
 
e284f77
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6775045
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
```javascript
// Initialize Vanta.js background animation
function initVantaBackground() {
    VANTA.NET({
        el: "#vanta-background",
        mouseControls: true,
        touchControls: true,
        gyroControls: false,
        minHeight: 200.00,
        minWidth: 200.00,
        scale: 1.00,
        scaleMobile: 1.00,
        color: 0x6366f1,
        backgroundColor: 0xf8fafc,
        points: 10.00,
        maxDistance: 22.00,
        spacing: 18.00
    });
}

// Initialize Feather Icons
function initFeatherIcons() {
    feather.replace();
}

// Cart functionality
let cart = [];

function updateCartCount() {
    const count = cart.reduce((total, item) => total + item.quantity, 0);
    document.querySelector('.cart-count').textContent = count;
    count > 0 
        ? document.querySelector('.cart-count').classList.remove('hidden') 
        : document.querySelector('.cart-count').classList.add('hidden');
}

function addToCart(productName, productPrice) {
    const existingItem = cart.find(item => item.name === productName);
    if(existingItem) {
        existingItem.quantity++;
    } else {
        cart.push({
            name: productName,
            price: productPrice,
            quantity: 1
        });
    }
    
    updateCartCount();
    showToast(`${productName} added to cart!`, 'success');
}

function showToast(message, type = 'success') {
    const toast = document.createElement('div');
    toast.className = `toast ${type}`;
    toast.textContent = message;
    document.body.appendChild(toast);
    
    setTimeout(() => {
        toast.classList.add('show');
        setTimeout(() => {
            toast.classList.remove('show');
            setTimeout(() => toast.remove(), 300);
        }, 2000);
    }, 100);
}

// Search functionality
function initSearch() {
    const searchInput = document.querySelector('input[type="text"]');
    if (searchInput) {
        searchInput.addEventListener('keyup', function(e) {
            if(e.key === 'Enter') {
                const searchTerm = this.value.toLowerCase();
                const products = document.querySelectorAll('.product-card');
                
                products.forEach(product => {
                    const name = product.querySelector('h3').textContent.toLowerCase();
                    const category = product.querySelector('p.text-gray-500').textContent.toLowerCase();
                    
                    if(name.includes(searchTerm) || category.includes(searchTerm)) {
                        product.style.display = 'block';
                    } else {
                        product.style.display = 'none';
                    }
                });
            }
        });
    }
}

// Mobile menu toggle
function initMobileMenu() {
    const mobileMenuButton = document.querySelector('.mobile-menu-button');
    const mobileMenu = document.querySelector('.mobile-menu');

    if (mobileMenuButton && mobileMenu) {
        mobileMenuButton.addEventListener('click', function() {
            mobileMenu.classList.toggle('show-mobile-menu');
        });

        // Close mobile menu when clicking outside
        document.addEventListener('click', function(e) {
            if (!mobileMenu.contains(e.target) && e.target !== mobileMenuButton) {
                mobileMenu.classList.remove('show-mobile-menu');
            }
        });
    }
}

// Product hover animations
function initProductHover() {
    document.querySelectorAll('.product-card').forEach(card => {
        card.addEventListener('mouseenter', function() {
            anime({
                targets: this.querySelector('img'),
                scale: 1.05,
                duration: 300,
                easing: 'easeOutQuad'
            });
        });
        
        card.addEventListener('mouseleave', function() {
            anime({
                targets: this.querySelector('img'),
                scale: 1,
                duration: 300,
                easing: 'easeOutQuad'
            });
        });
    });
}

// Form handling
function initForms() {
    // Login form
    const loginForm = document.getElementById('loginForm');
    if (loginForm) {
        loginForm.addEventListener('submit', function(e) {
            e.preventDefault();
            const email = document.getElementById('email').value;
            const password = document.getElementById('password').value;
            
            // Here you would typically send this to your backend
            console.log('Login attempt with:', { email, password });
            
            // For demo purposes, we'll just redirect
            window.location.href = 'index.html';
        });
    }

    // Register form
    const registerForm = document.getElementById('registerForm');
    if (registerForm) {
        registerForm.addEventListener('submit', function(e) {
            e.preventDefault();
            // Handle registration logic here
        });
    }
}

// Initialize all functionality when DOM is loaded
document.addEventListener('DOMContentLoaded', function() {
    initVantaBackground();
    initFeatherIcons();
    initSearch();
    initMobileMenu();
    initProductHover();
    initForms();

    // Add cart icon to nav if it doesn't exist
    if (!document.querySelector('.cart-icon')) {
        const navCart = document.createElement('div');
        navCart.className = 'cart-icon ml-4 relative cursor-pointer';
        navCart.innerHTML = `
            <i data-feather="shopping-bag" class="text-gray-500 hover:text-primary"></i>
            <span class="cart-count absolute -top-1 -right-1 bg-red-500 text-white text-xs rounded-full h-5 w-5 flex items-center justify-center hidden">0</span>
        `;
        document.querySelector('nav .hidden.sm\\:ml-6.sm\\:flex.sm\\:items-center').prepend(navCart);
        feather.replace();
    }

    // Set up event listeners for all "Add to cart" buttons
    document.querySelectorAll('.add-to-cart').forEach(button => {
        button.addEventListener('click', function() {
            const productCard = this.closest('.product-card');
            const productName = productCard.querySelector('h3').textContent;
            const productPrice = parseFloat(productCard.querySelector('.product-price').textContent.replace('$', ''));
            addToCart(productName, productPrice);
        });
    });
});

// Reinitialize Feather Icons when new content is loaded (like AJAX)
document.addEventListener('feather-icons-update', function() {
    feather.replace();
});
```