import { Swiper, SwiperSlide } from 'swiper/react'
import usePreferredBrand from '../hooks/usePreferredBrand'
import PreferredBrandSkeleton from './Skeleton/PreferredBrandSkeleton'
import BrandCard from '@/lib/brand/components/BrandCard'
import useDevice from '@/core/hooks/useDevice'
import Link from '@/core/components/elements/Link/Link'

const PreferredBrand = () => {
  const { preferredBrands } = usePreferredBrand()
  const { isMobile, isDesktop } = useDevice()

  return (
    <div className='px-4 sm:px-0'>
      <div className='flex justify-between items-center mb-4'>
        <div className='font-medium sm:text-h-lg'>Brand Pilihan</div>
        {isDesktop && (
          <Link href='/shop/brands' className='btn-yellow !text-gray_r-12'>
            Lihat Semua
          </Link>
        )}
      </div>
      {preferredBrands.isLoading && <PreferredBrandSkeleton />}
      {!preferredBrands.isLoading && (
        <Swiper slidesPerView={isMobile ? 3.5 : 7.5} spaceBetween={isMobile ? 12 : 24} freeMode>
          {preferredBrands.data?.manufactures.map((brand) => (
            <SwiperSlide key={brand.id}>
              <BrandCard brand={brand} />
            </SwiperSlide>
          ))}
        </Swiper>
      )}
    </div>
  )
}

export default PreferredBrand
