// Main application JavaScript
// This file contains general application functionality

// Initialize application when DOM is ready
document.addEventListener('DOMContentLoaded', function() {
    console.log('CodePress CMS initialized');
    
    // Handle nested dropdowns for touch devices
    const dropdownSubmenus = document.querySelectorAll('.dropdown-submenu');
    
    dropdownSubmenus.forEach(function(submenu) {
        const toggle = submenu.querySelector('.dropdown-toggle');
        const dropdown = submenu.querySelector('.dropdown-menu');
        
        if (toggle && dropdown) {
            // Prevent default link behavior
            toggle.addEventListener('click', function(e) {
                e.preventDefault();
                e.stopPropagation();
                
                // Close other submenus at the same level
                const parent = submenu.parentElement;
                parent.querySelectorAll('.dropdown-submenu').forEach(function(sibling) {
                    if (sibling !== submenu) {
                        sibling.querySelector('.dropdown-menu').classList.remove('show');
                    }
                });
                
                // Toggle current submenu
                dropdown.classList.toggle('show');
            });
            
            // Close submenu when clicking outside
            document.addEventListener('click', function(e) {
                if (!submenu.contains(e.target)) {
                    dropdown.classList.remove('show');
                }
            });
        }
    });
});