document.addEventListener('DOMContentLoaded', function() { // Mobile menu toggle document.addEventListener('click', function(e) { if (e.target.closest('.mobile-menu-btn')) { const navbar = document.querySelector('custom-navbar').shadowRoot.querySelector('.nav-links'); navbar.style.display = navbar.style.display === 'flex' ? 'none' : 'flex'; } }); // Smooth scrolling for anchor links document.querySelectorAll('a[href^="#"]').forEach(anchor => { anchor.addEventListener('click', function(e) { e.preventDefault(); document.querySelector(this.getAttribute('href')).scrollIntoView({ behavior: 'smooth' }); }); }); // Live update notification if ('serviceWorker' in navigator) { navigator.serviceWorker.register('/sw.js').then(registration => { registration.addEventListener('updatefound', () => { const newWorker = registration.installing; newWorker.addEventListener('statechange', () => { if (newWorker.state === 'installed') { showUpdateNotification(); } }); }); }); } // Feature card animations const featureCards = document.querySelectorAll('.feature-card'); featureCards.forEach((card, index) => { card.style.animationDelay = `${index * 100}ms`; card.classList.add('animate-fade-in'); }); // Real-time dashboard updates (example) function updateDashboardStats() { fetch('https://api.vanityvault.example/stats') .then(response => response.json()) .then(data => { // Update stats on dashboard page if (document.getElementById('dashboard-stats')) { document.getElementById('total-products').textContent = data.products; document.getElementById('low-stock').textContent = data.lowStock; document.getElementById('monthly-spend').textContent = `$${data.monthlySpend}`; } }); } // Check for updates every 5 minutes setInterval(updateDashboardStats, 300000); updateDashboardStats(); }); function showUpdateNotification() { const notification = document.createElement('div'); notification.className = 'fixed bottom-4 right-4 bg-purple-600 text-white px-4 py-3 rounded-lg shadow-lg z-50'; notification.innerHTML = `

A new version of VanityVault is available!

`; document.body.appendChild(notification); setTimeout(() => notification.remove(), 10000); } // User role management function checkUserRole() { const role = localStorage.getItem('userRole') || 'owner'; if (role === 'employee') { document.querySelectorAll('.admin-only').forEach(el => el.style.display = 'none'); } } // Initialize role check on dashboard pages if (window.location.pathname.includes('dashboard')) { checkUserRole(); }