/**
 * Minimal JavaScript for legal pages (Impressum & Datenschutz)
 * Only includes necessary functionality for language switching
 */

// Set current year in footer
function setCurrentYear() {
    const currentYear = new Date().getFullYear();
    const yearElements = document.querySelectorAll('.current-year');
    yearElements.forEach(element => {
        element.textContent = currentYear;
    });
}

// Simple language toggle for legal pages
document.addEventListener('DOMContentLoaded', function() {
    // Set current year immediately
    setCurrentYear();
    
    // Get the language toggle button
    const langToggle = document.querySelector('.lang-toggle');
    
    if (langToggle) {
        langToggle.addEventListener('click', function(e) {
            e.preventDefault();
            
            // Get current language from button
            const currentLang = this.getAttribute('data-lang') || 'de';
            const newLang = currentLang === 'de' ? 'en' : 'de';
            
            // Store language preference
            if (typeof(Storage) !== 'undefined') {
                localStorage.setItem('aegissight_language', newLang);
            }
            
            // Get current page name
            const currentPage = window.location.pathname.split('/').pop();
            
            // Determine redirect URL
            let redirectUrl = '';
            
            if (currentPage === 'impressum.html' || currentPage === 'impressum-en.html') {
                redirectUrl = newLang === 'en' ? 'impressum-en.html' : 'impressum.html';
            } else if (currentPage === 'datenschutz.html' || currentPage === 'datenschutz-en.html') {
                redirectUrl = newLang === 'en' ? 'datenschutz-en.html' : 'datenschutz.html';
            }
            
            // Redirect to the appropriate version
            if (redirectUrl) {
                window.location.href = redirectUrl;
            }
        });
    }
});