let cart = []; // Product data const products = { 'day-pass': { name: 'Day Pass', price: 5, duration: '24 hours', image: 'http://static.photos/red/200x200/1' }, 'week-pass': { name: 'Week Pass', price: 30, duration: '7 days', image: 'http://static.photos/red/200x200/2' }, 'month-pass': { name: 'Month Pass', price: 100, duration: '30 days', image: 'http://static.photos/red/200x200/3' } }; // Add to cart function function addToCart(productId) { cart.push(products[productId]); updateCart(); openCart(); } // Update cart display function updateCart() { const cartItemsEl = document.getElementById('cartItems'); const cartTotalEl = document.getElementById('cartTotal'); const checkoutItemsEl = document.getElementById('checkoutItems'); const checkoutTotalEl = document.getElementById('checkoutTotal'); // Clear existing items cartItemsEl.innerHTML = ''; // Add each item to cart display cart.forEach(item => { const itemEl = document.createElement('div'); itemEl.className = 'flex justify-between py-2 border-b border-gray-700'; itemEl.innerHTML = `
${item.name}

${item.name}

${item.duration}

₱${item.price}
`; cartItemsEl.appendChild(itemEl); }); // Calculate total const total = cart.reduce((sum, item) => sum + item.price, 0); cartTotalEl.textContent = `₱${total}`; // Update checkout summary checkoutItemsEl.textContent = `${cart.length} item${cart.length !== 1 ? 's' : ''}`; checkoutTotalEl.textContent = `₱${total}`; } // Cart modal functions function openCart() { document.getElementById('cartModal').classList.remove('hidden'); } function closeCart() { document.getElementById('cartModal').classList.add('hidden'); } // Checkout functions function proceedToCheckout() { closeCart(); document.getElementById('checkoutModal').classList.remove('hidden'); } function closeCheckout() { document.getElementById('checkoutModal').classList.add('hidden'); } // Payment functions function proceedToPayment() { const email = document.getElementById('email').value; if (!email) { alert('Please enter your email address'); return; } closeCheckout(); // Set payment details const total = cart.reduce((sum, item) => sum + item.price, 0); document.getElementById('paymentAmount').textContent = `₱${total}`; document.getElementById('paymentEmail').textContent = email; document.getElementById('paymentModal').classList.remove('hidden'); } function closePayment() { document.getElementById('paymentModal').classList.add('hidden'); } function completePayment() { closePayment(); document.getElementById('successModal').classList.remove('hidden'); // In a real app, you would send the order to your backend here console.log('Order completed:', { email: document.getElementById('email').value, items: cart, total: cart.reduce((sum, item) => sum + item.price, 0) }); // Reset cart cart = []; updateCart(); } function closeSuccess() { document.getElementById('successModal').classList.add('hidden'); } // Initialize document.addEventListener('DOMContentLoaded', () => { updateCart(); });