import Link from "next/link"
import { useQuery } from "react-query"
import Image from "~/components/ui/image"
import { getBanner } from "~/services/banner"

const SideBanner = () => {
  const fetchSideBanner = useQuery({
    queryKey: 'sideBanner',
    queryFn: () => getBanner({ type: 'side-banner-search' })
  })

  const banner = fetchSideBanner?.data?.[0] || false

  return banner && (
    <>
      {banner.url && (
        <Link href={banner.url}>
          <Image src={banner.image} alt={banner.name} width={315} height={450} className='object-cover object-center rounded-lg' />
        </Link>
      )}

      {!banner.url && (
        <Image src={banner.image} alt={banner.name} width={315} height={450} className='object-cover object-center rounded-lg' />
      )}
    </>
  )
}

export default SideBanner