document.addEventListener('DOMContentLoaded', () => { const currentPage = window.location.pathname.split('/').pop() || 'index.html'; const navHTML = ` `; const header = document.querySelector('header'); if (header) header.innerHTML += navHTML; const pageMap = { '': 'index.html', 'index.html': 'index.html', 'clients.html': 'clients.html', 'client.html': 'clients.html', 'admin.html': 'admin.html', 'login.html': 'login.html' }; const activePage = pageMap[currentPage] || ''; document.querySelectorAll('nav a[data-page]').forEach(link => { if (link.dataset.page === activePage) { link.classList.add('active'); } }); fetch('/api/me') .then(r => r.json()) .then(data => { if (data.isAdmin) { document.getElementById('logoutLink').style.display = 'inline'; } }); document.addEventListener('click', (e) => { if (e.target.id === 'logoutLink') { e.preventDefault(); fetch('/api/logout', { method: 'POST' }) .then(() => { window.localStorage.removeItem('csrfToken'); window.location.href = '/login.html'; }); } }); });