(function ($) {
  "use strict";

  // ===== Scroll Up =========================================
  $(window).scroll(function () {
    if ($(this).scrollTop() > 100) {
      $('.scrollup').fadeIn();
      $('.header, .side-navbar, .login-Wrapper, .page-main-wrapper, .adjust-with-header').addClass('scrolled');
    } else {
      $('.scrollup').fadeOut();
      $('.header, .side-navbar, .login-Wrapper, .page-main-wrapper, .adjust-with-header').removeClass('scrolled');
    }   

  });

  $(document).ready(function () {
    $('.scrollup').click(function (e) {
      e.preventDefault();
      $('html, body').animate({ scrollTop: 0 }, 600);
    });
  });



  // ===== Hide offset menu while open modal =========================================
  const modalEl = document.getElementById('booking-form');
  const offcanvasEl = document.getElementById('offcanvasNavbar');

  if (modalEl && offcanvasEl && window.bootstrap && bootstrap.Offcanvas) {
    modalEl.addEventListener('show.bs.modal', function () {
      const offcanvas = bootstrap.Offcanvas.getInstance(offcanvasEl);
      if (offcanvas) {
        offcanvas.hide();
      }
    });
  }



  // ===== Smooth scroll same page =========================================
  $('.anchor-link').click(function (e) {
    e.preventDefault();
    var target = $($(this).attr('href'));
    if (target.length) {
      $('html, body').animate({ scrollTop: target.offset().top }, 600);
    }
  });



// ===== sidebar =========================================  
  $(document).ready(function(){      
      $(".hamburger-menu").click(function(){
          $(".hamburger_icon").toggleClass("active");
          $(".header").toggleClass("active");
          $(".menu-wrapper-container").toggleClass("active");
          $(".sidebar-nav-wrapper").toggleClass("active-nav");
      }) 

      $(".click-verify").on("click", function () {
        $(this).toggleClass("active");
        // $(this).next().addClass("active");
        // $(this).prev().removeClass("active");
      });

      $(".calendar-approval-btn").on("click", function () {
        $(".calendar-approval-message, .calendar-approval-form").toggleClass("active");        
      });   

  });





  


 // ===== Country Code Selection ========================================= 
  $("#mobile-register-form, #mobile-profile-form").intlTelInput({
    initialCountry: "ae",
    separateDialCode: true,
    // utilsScript: "js/utils.js"
  });


 // ===== Radio Yes|No Div ========================================= 
  document.getElementById("yes").onclick = function () {
      document.getElementById("yesWrapper").style.display = "block";
      document.getElementById("noWrapper").style.display = "none";
  };

  document.getElementById("no").onclick = function () {
      document.getElementById("yesWrapper").style.display = "none";
      document.getElementById("noWrapper").style.display = "block";
  };









  // ===== Event-chk-list ========================================= 
  const list = document.querySelector('#events-chk-list ul.chk-list');
  const boxes = Array.from(list.querySelectorAll('input'));
  let lastChecked = null;

  list.addEventListener('click', (e) => {
    const target = e.target;
    if (target.tagName !== 'INPUT') return;

    if (e.shiftKey && lastChecked) {
      const start = boxes.indexOf(target);
      const end = boxes.indexOf(lastChecked);
      
      // Slice the array between the two indices and update checked state
      boxes.slice(Math.min(start, end), Math.max(start, end) + 1)
           .forEach(box => box.checked = target.checked);
    }

    lastChecked = target;
  });


  // ===== Step form ========================================= 
  let current = 0;

  const steps = document.querySelectorAll('.step-nav li');
  const contents = document.querySelectorAll('.content-display li.wrapper');
  const progressBar = document.getElementById('progressBar');
  const prevBtn = document.getElementById('prevBtn');
  const nextBtn = document.getElementById('nextBtn');

  function updateUI() {

      /* step nav class */
      steps.forEach((step, index) => {
          step.classList.toggle('active', index <= current);
      });

      /* content li add / remove class */
      contents.forEach((item, index) => {
          item.classList.remove('active');
      });

      contents[current].classList.add('active');

      /* progress bar */
      let progress = (current / (steps.length - 1)) * 100;
      progressBar.style.width = progress + '%';

      /* button disable */
      prevBtn.disabled = current === 0;
      nextBtn.disabled = current === steps.length - 1;
  }

  /* Next button */
  nextBtn.addEventListener('click', () => {
      if (current < contents.length - 1) {
          current++;
          updateUI();
      }
  });

  /* Prev button */
  prevBtn.addEventListener('click', () => {
      if (current > 0) {
          current--;
          updateUI();
      }
  });

  /* Step navigation click */
  steps.forEach((step, index) => {
      step.addEventListener('click', () => {
          current = index;
          updateUI();
      });
  });

  updateUI();











 





  // ===== AOS Initialization =========================================
  AOS.init({
    offset: 200,
    duration: 800,
    delay: 100,
    disable: () => window.innerWidth < 800,
  });


})(jQuery);