export function themeToggle() {
    const button = document.querySelector('#theme-toggle');
    const root = document.documentElement;
  
    if (!button) return;
  
    // Appliquer le thème sauvegardé (si présent)
    const savedTheme = localStorage.getItem('theme');
    if (savedTheme === 'light') {
      root.setAttribute('data-theme', 'light');
    }
  
    button.addEventListener('click', () => {
      const isLight = root.getAttribute('data-theme') === 'light';
      const nextTheme = isLight ? 'dark' : 'light';
  
      root.setAttribute('data-theme', nextTheme);
      localStorage.setItem('theme', nextTheme);
  
      button.setAttribute(
        'aria-label',
        nextTheme === 'light' ? 'Activer le mode sombre' : 'Activer le mode clair'
      );
    });
  }
  