$(document).ready(function () {
  // $(".carousel").carousel({ interval: 5000 });
  // $(".nav > li.dropdown > a").click(function (e) {
  //   var $target = $(e.target);
  //   var activeNav = $(this).siblings();
  //   if ($target.is("b")) {
  //     $(this).siblings().toggle("fast");
  //     $(".nav > li.dropdown > ul.dropdown-menu:visible")
  //       .not($(this).siblings())
  //       .hide("fast");
  //     return false;
  //   }
  // });
});

waitForElm(".autoplay .slick-slide").then((elm) => {
  $(".autoplay").slick({
    slidesToShow: 6,
    slidesToScroll: 1,
    autoplay: true,
    autoplaySpeed: 5000,
    prevArrow:
      "<button type='button' class='slick-prev slick-arrow position-absolute'><svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 26.598 15.21' width='26.598' height='15.21'> <path d='M26.386 1.4 25.2.212a.721.721 0 0 0-1.021 0L13.3 11.065 2.422.212a.721.721 0 0 0-1.022 0L.212 1.4a.721.721 0 0 0 0 1.021L12.788 15a.721.721 0 0 0 1.021 0L26.386 2.422a.721.721 0 0 0 0-1.022Z' fill='#fff'></path></svg></button>",
    nextArrow:
      "<button type='button' class='slick-next slick-arrow position-absolute'><svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 26.598 15.21' width='26.598' height='15.21'> <path d='M26.386 1.4 25.2.212a.721.721 0 0 0-1.021 0L13.3 11.065 2.422.212a.721.721 0 0 0-1.022 0L.212 1.4a.721.721 0 0 0 0 1.021L12.788 15a.721.721 0 0 0 1.021 0L26.386 2.422a.721.721 0 0 0 0-1.022Z' fill='#fff'></path></svg></button>",
    responsive: [
      {
        breakpoint: 1400,
        settings: {
          slidesToShow: 2,
          slidesToScroll: 1,
          infinite: true,
        },
      },
      {
        breakpoint: 576,
        settings: {
          slidesToShow: 1,
          slidesToScroll: 1,
          infinite: true,
        },
      },
    ],
  });
});

function waitForElm(selector) {
  return new Promise((resolve) => {
    if (document.querySelector(selector)) {
      return resolve(document.querySelector(selector));
    }
    const observer = new MutationObserver((mutations) => {
      if (document.querySelector(selector)) {
        resolve(document.querySelector(selector));
        observer.disconnect();
      }
    });
    observer.observe(document.body, {
      childList: true,
      subtree: true,
    });
  });
}
