document.addEventListener('DOMContentLoaded', function() {
  // Get all language switcher elements
  const langSwitchers = document.querySelectorAll('[data-lang-switch]');

  if (!langSwitchers || langSwitchers.length === 0) {
    return;
  }

  // Add click event listener to each language switcher
  langSwitchers.forEach(function(switcher) {
    switcher.addEventListener('click', function(e) {
      e.preventDefault();

      // Get the language code from the data attribute
      const langCode = this.getAttribute('data-lang-switch');

      // Store the language preference in localStorage
      localStorage.setItem('preferred-language', langCode);

      // Navigate to the language-specific URL
      window.location.href = this.href;
    });
  });
});
