document.getElementById('mobile-button').addEventListener('click', function () {
  const sidebar = document.getElementById('sidebar');
  if (!sidebar.classList.contains('shown')) {
    sidebar.classList.remove('hidden');
    sidebar.classList.add('shown');
  } else {
    sidebar.classList.remove('shown');
    sidebar.classList.add('hidden');
  }
});

document.addEventListener('DOMContentLoaded', function() {
  // Fonction pour afficher le bon ul au chargement de la page
  function showActiveNav() {
      let activeLink = document.querySelector('a.active');
      if (activeLink) {
          const parentUl = activeLink.closest('ul.nav');
          if (parentUl) {
              parentUl.style.display = 'block';
              
              const dataSelect = parentUl.classList[1];
              
              const activeButton = document.querySelector(`button[data-select="${dataSelect}"]`);
              if (activeButton) {
                  activeButton.classList.add('active');
              }
          }
      }
  }

  showActiveNav();

  const buttons = document.querySelectorAll('.sidebar-selector button');

  buttons.forEach(button => {
      button.addEventListener('click', function() {
          const selectedNav = this.getAttribute('data-select');

          document.querySelectorAll('ul.nav').forEach(nav => {
              nav.style.display = 'none';
          });

          const activeNav = document.querySelector(`ul.${selectedNav}`);
          if (activeNav) {
              activeNav.style.display = 'block';
          }

          buttons.forEach(btn => {
              btn.classList.remove('active');
          });

          this.classList.add('active');
      });
  });
});