/**
 * WTE Business Card — Header JS (Sticky scroll, Mobile menu)
 */
'use strict';
document.addEventListener('DOMContentLoaded', function() {
	const header = document.querySelector('.wte-header');
	const toggle = document.querySelector('.wte-header__menu-toggle');
	const mobileNav = document.getElementById('wte-mobile-nav');
	if (!header) return;

	// Mobile menu toggle.
	if (toggle && mobileNav) {
		toggle.addEventListener('click', function() {
			const isOpen = mobileNav.classList.toggle('is-open');
			toggle.setAttribute('aria-expanded', String(isOpen));
			mobileNav.setAttribute('aria-hidden', String(!isOpen));
			document.body.style.overflow = isOpen ? 'hidden' : '';

			// Animate hamburger.
			const lines = toggle.querySelectorAll('.wte-hamburger__line');
			if (isOpen) {
				lines[0].style.transform = 'rotate(45deg) translate(5px, 5px)';
				lines[1].style.opacity = '0';
				lines[2].style.transform = 'rotate(-45deg) translate(5px, -5px)';
			} else {
				lines[0].style.transform = '';
				lines[1].style.opacity = '';
				lines[2].style.transform = '';
			}
		});

		// Close on link click.
		mobileNav.querySelectorAll('a').forEach(function(link) {
			link.addEventListener('click', function() {
				mobileNav.classList.remove('is-open');
				toggle.setAttribute('aria-expanded', 'false');
				mobileNav.setAttribute('aria-hidden', 'true');
				document.body.style.overflow = '';
				const lines = toggle.querySelectorAll('.wte-hamburger__line');
				lines[0].style.transform = '';
				lines[1].style.opacity = '';
				lines[2].style.transform = '';
			});
		});
	}

	// Header shadow on scroll.
	let lastScroll = 0;
	window.addEventListener('scroll', function() {
		const scrollY = window.scrollY;
		if (scrollY > 10) {
			header.classList.add('wte-header--scrolled');
		} else {
			header.classList.remove('wte-header--scrolled');
		}
		lastScroll = scrollY;
	}, { passive: true });
});
