<script lang='ts' setup>
import { Swiper, SwiperSlide } from 'swiper/vue'
import { Navigation, Pagination } from 'swiper/modules'
import {
  getSimilarBrandListApi,
} from '~/api/model/brand'

// import "swiper/css/pagination"
import 'swiper/css'
import 'swiper/css/navigation'

const swiperVertical = ref<any>(null)
const modules = [Navigation, Pagination]
const similarBrandList = ref<any>([])

async function getSimilarBrandList() {
  try {
    const params = {
      pageNo: 1,
      pageSize: 20,
    }
    const data: any = await getSimilarBrandListApi(params)
    similarBrandList.value = data.records
  }
  catch (error) {
    console.log('error', error)
  }
}
function onVerticalSwiper(swiper: any) {
  swiperVertical.value = swiper
}
function onClickLeft() {
  swiperVertical.value.slidePrev()
}
function onClickRight() {
  swiperVertical.value.slideNext()
}
getSimilarBrandList()
</script>

<template>
  <div class="w-726px">
    <div class="m-auto pos-relative px-66px">
      <div
        v-if="similarBrandList.length"
        class="pos-absolute cursor-pointer left-10px top-58px w-28px h-28px transform-translate-y--50% cursor-not-allowed !cursor-pointer flex justify-center items-center"
        @click="onClickLeft()"
      >
        <img src="~/assets/images/arrow_left.png" alt="" class="w-26px h-26px" srcset="">
      </div>
      <div
        v-if="similarBrandList.length"
        class="pos-absolute cursor-pointer  right-10px top-58px w-28px h-28px transform-translate-y--50% cursor-not-allowed !cursor-pointer flex justify-center items-center"
        @click="onClickRight()"
      >
        <img src="~/assets/images/arrow_right.png" alt="" class="w-26px h-26px" srcset="">
      </div>
      <Swiper
        :slides-per-view="4"
        :space-between="50"
        :modules="modules"
        :loop="true"
        :navigation="false"
        :pagination="true"
        class="pos-relative"
        @swiper="onVerticalSwiper"
      >
        <SwiperSlide v-for="(item, index) in similarBrandList" :key="index">
          <div class="text-center">
            <img
              :src="item.thumbnail || item.masterImage"
              alt=""
              srcset=""
              class="w-80px h-80px object-cover b-rd-50% mx-auto"
            >
            <h3
              class="!mt-16px"
            >
              {{ item.brandName }}
            </h3>
          </div>
        </SwiperSlide>
      </Swiper>
    </div>
  </div>
</template>

<style lang='less' scoped>
</style>
