document.querySelectorAll('nav ul li a').forEach(link => {
  link.addEventListener('click', e => {
    e.preventDefault();
    const target = e.target.id.replace('nav-', '') + '-section';
    document.querySelectorAll('main section').forEach(sec => sec.classList.add('hidden'));
    const section = document.getElementById(target);
    if (section) section.classList.remove('hidden');
  });
});

/*
onload
*/

document.addEventListener("DOMContentLoaded", function() {
	const loadingScreen = document.getElementById('loading-screen');

	loadingScreen.addEventListener('click', function() {
		loadingScreen.style.display = 'none';
		const container = document.querySelector(".foreground-container");
		container.classList.remove("hidden");
		container.classList.add("fade-in");
		const container2 = document.querySelector(".navbar-container");
		container2.classList.remove("hidden");
		container2.classList.add("fade-in");
	});
});

function filterContent() {
	const query = document.getElementById('searchInput').value.toLowerCase();
	document.querySelectorAll('.section').forEach(section => {
		const text = section.innerText.toLowerCase();
		section.style.display = text.includes(query) ? 'block' : 'none';
	});
}

function downloadOfflineVersion() {
	const blob = new Blob([document.documentElement.outerHTML], { type: 'text/html' });
	const a = document.createElement('a');
	a.href = URL.createObjectURL(blob);
	a.download = 'SystemsLangDocumentation.html';
	a.click();
}

function toggleSearch() {
	const dropdown = document.getElementById('searchDropdown');
	dropdown.style.display = dropdown.style.display === 'block' ? 'none' : 'block';
}
