class CustomHeader extends HTMLElement {
connectedCallback() {
this.attachShadow({ mode: 'open' });
this.shadowRoot.innerHTML = `
`;
// Mobile menu toggle
const mobileMenuBtn = this.shadowRoot.getElementById('mobileMenuBtn');
const navLinks = this.shadowRoot.getElementById('navLinks');
mobileMenuBtn.addEventListener('click', () => {
navLinks.classList.toggle('mobile-open');
});
// Set active link based on current page
const currentPath = window.location.pathname;
const navLinksElements = this.shadowRoot.querySelectorAll('.nav-link');
navLinksElements.forEach(link => {
const href = link.getAttribute('href');
if ((currentPath === '/' && href === '/') ||
(currentPath !== '/' && href === currentPath) ||
(currentPath.endsWith(href) && href !== '/')) {
link.classList.add('active');
}
});
}
}
customElements.define('custom-header', CustomHeader);