<template>
  <section :class="['tw-relative xl:tw-max-w-[1246px] xl:tw-mx-auto']">
    <div class="swiper-container advertisementMode" ref="advertisementMode"
      @mouseenter="enter" @mouseleave="leave">
      <div :class="['swiper-wrapper']">
        <div v-for="(item, index) in advertisementList" :key="index" :class="['swiper-slide']">
          <div>
            <lazyImg :src="item.image" :customClass="'swiper-lazy'"></lazyImg>
          </div>
        </div>
      </div>
      <div class="swiper-pagination tw-hidden" slot="pagination"></div>
    </div>
    <!-- <div :class="[
      'swiper-button-prev ad tw-text-black tw-hidden',
      advertisementSwiper ? 'xl:tw-block' : '',
    ]"></div>
    <div :class="[
      'swiper-button-next ad tw-text-black tw-hidden',
      advertisementSwiper ? 'xl:tw-block' : '',
    ]"></div> -->
  </section>
</template>
<script>
import Swiper from "swiper/bundle";
import lazyImg from "@/components/img/img.vue";
export default {
  components: {
    Swiper,
    lazyImg,
  },
  props: {
    advertisementList: {
      type: Array,
    },
  },
  data() {
    return {
      advertisementSwiper: null,
    };
  },
  mounted() {
    let vm = this;
    vm.$nextTick(function () {
      vm.advertisementSwiper = new Swiper(".swiper-container.advertisementMode", {
        direction: "horizontal",
        initialSlide: 1,
        centeredSlidesBounds: true,
        slidesPerView: 1,
        centeredSlides: true,
        loop: true,
        loopedSlides: 0,
        observer: true, //修改swiper自己或子元素时，自动初始化swiper
        observeParents: true, //修改swiper的父元素时，自动初始化swiper
        spaceBetween: 20,
        autoplay: {
          disableOnInteraction: true,
          delay: 5000,
        },
        preloadImages: false,
        lazy: {
          loadPrevNext: true,
          loadOnTransitionStart: true,
          loadPrevNextAmount: 6,
        },
        watchSlidesProgress: true,
        // navigation: {
        //   nextEl: ".swiper-button-next.ad",
        //   prevEl: ".swiper-button-prev.ad",
        // },
        pagination:{
          el: ".swiper-pagination",
          clickable: true,
        },
        breakpoints: {
          768: {
            slidesPerView: 1,
            spaceBetween: 20,
          },
          1366: {
            slidesPerView: 1,
            spaceBetween: 20,
            centeredSlides: false,
            grabCursor: true,
          },
        },
      });
      vm.advertisementSwiper.init();
      vm.advertisementSwiper.update();
    });
  },
  methods: {
    enter() {
      this.advertisementSwiper.autoplay.stop();
    },
    leave() {
      this.advertisementSwiper.autoplay.start();
    },
  },
};
</script>
<style>
.swiper-container {
  width: 100% !important;
}

.pagination {
  position: absolute;
  z-index: 20;
  bottom: 10px;
  width: 100%;
  text-align: center;
}
.swiper-pagination-switch {
  display: inline-block;
  width: 12px;
  height: 12px;
  /* border-radius: 16px; */
  background: #c1c3c2;
  margin: 0 15px;
  /* opacity: 0.8; */
  border: 1px solid #c1c3c2;
  cursor: pointer;
}
.swiper-active-switch {
  background: #d38217;
}

.swiper-pagination-bullet {
  background-color: #c1c3c2;
  width: 12px;
  height: 12px;
  border-radius: 12px;
  opacity: 1;
}
.swiper-pagination-bullet-active{
  background-color: #d38217;
  width: 12px;
  height: 12px;
  border-radius: 12px;
}

</style>
