jQuery(document).ready(function($) {
  var scrollup = $('.scroll-top');

  // Hide the scroll-to-top button initially
  scrollup.hide();

  /*------------------------------------------------
            Scroll Top
  ------------------------------------------------*/
  scrollup.click(function () {
    $('html, body').animate({
      scrollTop: '0px'
    }, 800);
    return false;
  });

  $(window).scroll(function () {
    var scroll = $(window).scrollTop();
    if (scroll >= 200) {
      scrollup.fadeIn();
    } else {
      scrollup.fadeOut();
    }
  });

  const section = $('.main-slider');
  const owl = section.find('.owl-carousel');
  const dots = section.find('.tabs-col .wp-block-column');

  owl.owlCarousel({
    loop: true,
    margin: 15,
    nav: false,
    dots: true,
    items: 1,
    animateOut: 'fadeOut',
    animateIn: 'fadeIn',
    smartSpeed: 600,
    mouseDrag: false,
    touchDrag: false,
    pullDrag: false,
    freeDrag: false,
    autoplay: true
  });

  /* ---- Click on existing buttons ---- */
  dots.each(function(index){
    $(this).on('click', function(e){
      e.preventDefault();
      owl.trigger('to.owl.carousel', [index, 600, true]);
    });
  });

  /* ---- Update Active Button ---- */
  owl.on('changed.owl.carousel', function(e){
    let index = (e.item.index - e.relatedTarget._clones.length / 2 + e.item.count) % e.item.count;

    dots.removeClass('active')
        .eq(index)
        .addClass('active');
  });

  dots.eq(0).addClass('active');
});