jQuery(document).ready(function ($) {
	// Toggle sidebar collapse
	$('#hamburger').click(function () {
		$('#sidebar-wrapper').toggleClass('collapsed');
		localStorage.setItem('sidebarCollapsed', $('#sidebar-wrapper').hasClass('collapsed'));
	});

	// Restore collapsed state from localStorage
	if (localStorage.getItem('sidebarCollapsed') === 'true') {
		$('#sidebar-wrapper').addClass('collapsed');
	}

	// Highlight active menu item
	function getPageFromURL() {
		 const path = window.location.pathname;
         const match = path.match(/\/user-dashboard\/([^\/]*)/);
        return match && match[1] ? match[1] : "dashboard";
	}

	function setActiveMenuItem() {
		let currentPage = getPageFromURL();
		$('.menu-item,.submenu-item').each(function () {
			let page = $(this).data('page');
			$(this).toggleClass('active', page === currentPage);
		});
	}

	$('.menu-item ,.submenu-item').on('click', function () {
		$('.menu-item ,.submenu-item').removeClass('active');
		$(this).addClass('active');
	});

	setActiveMenuItem();
});


function voidempoInitializeTooltips() {
	const tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'));
	tooltipTriggerList.map(function (tooltipTriggerEl) {
		return new bootstrap.Tooltip(tooltipTriggerEl);
	});
}
