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 fse_renovation_services_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",
    },
  });

  // service slider
  var fse_renovation_services_service_Slider = new Swiper(".service-slider", {
    breakpoints: {
      0: {
        slidesPerView: 1,
      },
      768: {
        slidesPerView: 2,
      },
      992: {
        slidesPerView: 4,

      }
    },
    autoplay: {
      delay: 3000,
      disableOnInteraction: false,
    },
    spaceBetween: 30,
    loop: true,
    navigation: {
      nextEl: ".service-swiper-button-next",
      prevEl: ".service-swiper-button-prev",
    },
  });

/*slick slider*/
const options = {
  slidesToShow: 1,
  slidesToScroll: 1,
  dots: true,
  arrows: false,
  adaptiveHeight: true,
  autoplay: false
};

const mySlider = jQuery('.slider').on('init', function(event, slick) {
  const slider = this;

  // Slight delay to ensure DOM is fully rendered
  setTimeout(function() {
    // Get all dot buttons inside this slider
    let dots = jQuery('.slick-dots > li > button', slider);

    jQuery.each(dots, function(i, button) {
      // Get slide ID from aria-controls attribute
      let slide_id = jQuery(button).attr('aria-controls');

      // Get the actual slide by ID
      let slide = jQuery('#' + slide_id);

      // Find the cover image inside the slide
      let imgEl = slide.find('.wp-block-cover__image-background');

      // Extract the image source
      let dot_img = imgEl.attr('src');

      // Replace the dot with the image if available
      if (dot_img) {
        jQuery(button).html('<img src="' + dot_img + '" alt="Slide Thumbnail" />');
      }
    });

  }, 100);
}).slick(options);

});