<?php
// admin/footer.php
?>
        <!-- Page Content Ends Here -->
    </div>
</div>

<!-- ===== SCRIPTS ===== -->
<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>

<script>
// ========================================
// SIDEBAR TOGGLE (Mobile)
// ========================================
function toggleSidebar() {
    var sidebar = document.getElementById('adminSidebar');
    var overlay = document.getElementById('sidebarOverlay');
    
    sidebar.classList.toggle('open');
    overlay.classList.toggle('active');
    
    // Prevent body scroll when sidebar is open
    document.body.style.overflow = sidebar.classList.contains('open') ? 'hidden' : '';
}

function closeSidebar() {
    var sidebar = document.getElementById('adminSidebar');
    var overlay = document.getElementById('sidebarOverlay');
    
    sidebar.classList.remove('open');
    overlay.classList.remove('active');
    document.body.style.overflow = '';
}

// Close sidebar on escape key
document.addEventListener('keydown', function(e) {
    if (e.key === 'Escape') {
        closeSidebar();
    }
});

// ========================================
// SUBMENU TOGGLE
// ========================================
function toggleSubmenu(element) {
    element.classList.toggle('open');
    var submenu = element.nextElementSibling;
    if (submenu && submenu.classList.contains('submenu')) {
        submenu.classList.toggle('open');
    }
}

// ========================================
// ACTIVE SUBMENU ITEM - Keep submenu open when a child is active
// ========================================
document.addEventListener('DOMContentLoaded', function() {
    // Find active submenu items
    var activeSubmenuItems = document.querySelectorAll('.submenu li a.active');
    activeSubmenuItems.forEach(function(item) {
        var submenu = item.closest('.submenu');
        if (submenu) {
            submenu.classList.add('open');
            var parentLink = submenu.previousElementSibling;
            if (parentLink && parentLink.classList.contains('has-submenu')) {
                parentLink.classList.add('open');
            }
        }
    });
    
    // Auto close sidebar on desktop when window is resized
    if (window.innerWidth > 768) {
        closeSidebar();
    }
});

// ========================================
// TOAST NOTIFICATION
// ========================================
function showToast(message, type) {
    var colors = {
        success: '#22c55e',
        error: '#ef4444',
        warning: '#f59e0b',
        info: '#3b82f6'
    };
    
    var toast = document.createElement('div');
    toast.style.cssText = `
        position: fixed;
        top: 20px;
        right: 20px;
        padding: 12px 24px;
        background: ${colors[type] || colors.info};
        color: #fff;
        border-radius: 8px;
        z-index: 9999;
        box-shadow: 0 5px 20px rgba(0,0,0,0.15);
        animation: slideIn 0.3s ease;
        max-width: 400px;
        font-size: 14px;
        font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    `;
    toast.textContent = message;
    document.body.appendChild(toast);
    
    setTimeout(function() {
        toast.style.opacity = '0';
        toast.style.transition = 'opacity 0.3s ease';
        setTimeout(function() { toast.remove(); }, 300);
    }, 3000);
}

// ========================================
// CONFIRM DELETE
// ========================================
function confirmDelete(url, message) {
    if (confirm(message || 'Are you sure you want to delete this item?')) {
        window.location.href = url;
    }
}

// ========================================
// ADD CSS ANIMATIONS
// ========================================
var style = document.createElement('style');
style.textContent = `
    @keyframes slideIn {
        from { transform: translateX(100%); opacity: 0; }
        to { transform: translateX(0%); opacity: 1; }
    }
`;
document.head.appendChild(style);

// ========================================
// AUTO CLOSE SIDEBAR ON RESIZE TO DESKTOP
// ========================================
window.addEventListener('resize', function() {
    if (window.innerWidth > 768) {
        closeSidebar();
    }
});

console.log('Admin Panel Loaded Successfully!');
</script>

</body>
</html>