document.addEventListener('DOMContentLoaded', function () {
  const toggle = document.getElementById('lang-switch');

  if (!toggle) return;

  toggle.addEventListener('click', function () {
    toggle.classList.toggle('toggle-on');

    // Detect current URL and language
    const currentURL = window.location.href;
    if (currentURL.includes('/ar/')) {
      window.location.href = currentURL.replace('/ar/', '/en/');
    } else if (currentURL.includes('/en/')) {
      window.location.href = currentURL.replace('/en/', '/ar/');
    } else {
      // Default fallback (adjust as needed)
      window.location.href = currentURL.includes('/ar') ? '/' : '/ar/';
    }
  });
});
