document.addEventListener("DOMContentLoaded", function () {
    // Get current filename (e.g., 'admin_profile.php')
    const path = window.location.pathname;
    const currentPage = path.split('/').pop();

    document.querySelectorAll('.sb-sidenav-menu a.nav-link').forEach(link => {
        const href = link.getAttribute('href');
        if (!href || href === "#") return;

        // More robust matching: checks if the current URL ends with or includes the href
        if (currentPage === href || path.endsWith(href)) {
            
            // 1. Add active class to the link itself
            link.classList.add('active');

            // 2. Handle Parent Collapses (if this link is inside a menu)
            const collapse = link.closest('.collapse');
            if (collapse) {
                collapse.classList.add('show');

                // Find the link that toggles this collapse
                const parentLink = document.querySelector(
                    `[data-bs-target="#${collapse.id}"]`
                );

                if (parentLink) {
                    parentLink.classList.remove('collapsed');
                    parentLink.classList.add('active');
                    parentLink.setAttribute('aria-expanded', 'true');
                }
            }
        }
    });
});
//=============== scholl setting ===============
// Function to open modal and load existing data
