// Authentication state let isAuthenticated = false; let currentUser = null; // Check authentication on page load function checkAuth() { const token = localStorage.getItem('authToken'); if (token && window.location.pathname.includes('login.html')) { window.location.href = 'index.html'; } else if (!token && !window.location.pathname.includes('login.html')) { window.location.href = 'login.html'; } } // Login function function login(email, password) { // In a real app, this would be an API call if (email === 'admin@shopsphere.com' && password === 'admin123') { localStorage.setItem('authToken', 'dummy-token'); localStorage.setItem('userRole', 'admin'); isAuthenticated = true; currentUser = { email, role: 'admin' }; return true; } return false; } // Logout function function logout() { localStorage.removeItem('authToken'); localStorage.removeItem('userRole'); isAuthenticated = false; currentUser = null; window.location.href = 'login.html'; } document.addEventListener('DOMContentLoaded', function() { checkAuth(); // Handle login form submission const loginForm = document.getElementById('login-form'); if (loginForm) { loginForm.addEventListener('submit', function(e) { e.preventDefault(); const email = document.getElementById('email').value; const password = document.getElementById('password').value; if (login(email, password)) { window.location.href = 'index.html'; } else { alert('Invalid credentials'); } }); } // Sample product data - in a real app, this would come from an API const products = [ { id: 1, name: 'Wireless Headphones', price: 99.99, stock: 45, image: 'http://static.photos/technology/200x200/1' }, { id: 2, name: 'Smart Watch', price: 199.99, stock: 12, image: 'http://static.photos/technology/200x200/2' }, { id: 3, name: 'Bluetooth Speaker', price: 59.99, stock: 30, image: 'http://static.photos/technology/200x200/3' } ]; // Render products table const productsTable = document.getElementById('products-table'); if (productsTable) { products.forEach(product => { const row = document.createElement('tr'); row.className = 'hover:bg-gray-50'; row.innerHTML = `