document.addEventListener('DOMContentLoaded', function () {
    document.querySelectorAll('#adminmenu a[href*="page=cpbw"]').forEach(function (link) {
        link.addEventListener('click', function (e) {
            var href = link.getAttribute('href');
            var hashMatch = href.match(/#(\/[^"]*)/);
            var hash = hashMatch ? hashMatch[1] : '/';

            if (window.location.href.includes('page=cpbw')) {
                e.preventDefault();
                window.location.hash = hash;

                document.querySelectorAll('#adminmenu li').forEach(function (li) {
                    li.classList.remove('current');
                });
                link.closest('li')?.classList.add('current');
            }
        });
    });
});