import 'swiper/css'

import React from 'react'
import { Swiper, SwiperSlide } from 'swiper/react'
import { FreeMode } from 'swiper'

import ProductCard from '~/modules/product-card'
import { IProduct } from '~/types/product'
import useDevice from '@/core/hooks/useDevice'

type Props = {
  products: IProduct[],
  productLayout?: 'vertical' | 'horizontal',
}

const ProductSlider = ({ products, productLayout }: Props) => {
  const { isDesktop, isMobile } = useDevice()

  return (
    <div>
      <Swiper
        slidesPerView={isDesktop ? 6.7 : 1.85}
        spaceBetween={isDesktop ? 16 : 12}
        prefix='product-slider'
        modules={[FreeMode]}
        freeMode={{ enabled: true, sticky: false }}
        className='!pb-0.5'
      >
        {products.map((product) => (
          <SwiperSlide key={product.id}>
            <ProductCard
              product={product}
              layout={productLayout}
            />
          </SwiperSlide>
        ))}
      </Swiper>
    </div >
  )
}

export default ProductSlider