jQuery(document).ready(function ($) {

  $(window).scroll(function () {
    if ($(this).scrollTop() > 100) {
      $(".back-to-top a").fadeIn();
    } else {
      $(".back-to-top a").fadeOut();
    }
  });

  $(".back-to-top a").click(function () {
    $("html, body").animate({ scrollTop: 0 }, 800);
    return false;
  });

  //projects-swiper
  var coffee_shop_bistro_project_Slider = new Swiper(".projects-slider", {
    breakpoints: {
      0: {
        slidesPerView: 1,
        centeredSlides: false,
      },
      768: {
        slidesPerView: 2,
        centeredSlides: false,
      },
      992: {
        slidesPerView: 3,
        centeredSlides: true,
      }
    },
    autoplay: {
      delay: 3000,
      disableOnInteraction: false,
    },
    spaceBetween: 30,
    loop: true,
    navigation: {
      nextEl: ".projects-swiper-button-next",
      prevEl: ".projects-swiper-button-prev",
    },
  });

});

document.addEventListener('DOMContentLoaded', function () {
  const coffee_shop_bistro_counters = document.querySelectorAll('.customer-no');
  coffee_shop_bistro_counters.forEach(function (counter) {
    const coffee_shop_bistro_target = parseInt(counter.textContent.replace(/\D/g, ''), 10); // base 10
    const coffee_shop_bistro_duration = 2000; // total coffee_shop_bistro_duration (ms)
    const coffee_shop_bistro_startTime = performance.now();

    function coffee_shop_bistro_updateCounter(currentTime) {
      const elapsed = currentTime - coffee_shop_bistro_startTime;
      const progress = Math.min(elapsed / coffee_shop_bistro_duration, 1);
      const count = Math.floor(progress * coffee_shop_bistro_target);

      counter.textContent = count;

      if (progress < 1) {
        requestAnimationFrame(coffee_shop_bistro_updateCounter);
      } else {
        counter.textContent = coffee_shop_bistro_target; // ensure final value
      }
    }

    requestAnimationFrame(coffee_shop_bistro_updateCounter);
  });
});