import Image from 'next/image'
import useCategoryHome from '../hooks/useCategoryHome'
import Link from '@/core/components/elements/Link/Link'
import { createSlug } from '@/core/utils/slug'
import { useEffect, useState } from 'react';
import { bannerApi } from '../../../api/bannerApi';
const { useQuery } = require('react-query')
import { HeroBannerSkeleton } from '../../../components/skeleton/BannerSkeleton';
import useCategoryPilihan from '../hooks/useCategoryPilihan';

const CategoryPilihan = ({ id, categories }) => {
    const { categoryPilihan } = useCategoryPilihan();
    const heroBanner = useQuery('categoryPilihan', bannerApi({ type: 'banner-category-list' }));
      return (
          <section>
        <div className='flex flex-row items-center mb-4'>
            <div className='font-semibold sm:text-h-lg mr-2'>Kategori Pilihan</div>
            <p className='text-gray_r-10 text-sm'>200 Rb+ Produk Unggulan & 800+ Brand Rekomendasi tersedia!</p>
        </div>
        <div className='flex w-full h-48 bg-red-300 mb-4'>
            {heroBanner.data &&
                heroBanner.data?.length > 0 && (
                    <div className='px-4 sm:px-0  object-fill '>
                        {/* {heroBanner.data?.map((banner) => ( */}
                            <Link key={heroBanner.data[0].id} href={heroBanner.data[0].url}>
                                <Image
                                width={439}
                                height={150}
                                quality={100}
                                src={heroBanner.data[0].image}
                                alt={heroBanner.data[0].name}
                                className='h-48 object-fill w-full'
                                />
                            </Link>
                            {/* ))} */}
                    </div>
                
                )}
        </div>
        <div className="group/item grid grid-cols-6 gap-y-2 w-full h-full col-span-2 ">
                {categoryPilihan?.data?.map((category) => (
                    <div key={category.id} className="KartuInti h-48 w-60 max-w-sm   lg:max-w-full flex flex-col   border-[1px] border-gray-200  relative group">
                        <div className='KartuB absolute h-48 w-60 inset-0 flex items-center justify-center '>
                            <div className="group/edit flex items-center justify-end h-48 w-60  flex-col group-hover/item:visible">
                                <div className=' h-36 flex justify-end items-end'>
                                    <Image className='group-hover:scale-105 transition-transform duration-300 ' src={category?.image? category?.image : '/images/noimage.jpeg'}  width={120} height={120} alt={category?.name} />
                                </div>
                                <h2 className="text-gray-700 content-center h-12 border-t-[1px] px-1 w-60 border-gray-200 font-normal text-sm text-center">{category?.industries}</h2>
                            </div>
                        </div>
                        <div className='KartuA relative inset-0  flex h-36 w-60   items-center justify-center opacity-0 group-hover:opacity-75 group-hover:bg-[#E20613] transition-opacity '>
                            <Link
                                href={createSlug('/shop/lob/', category?.industries, category?.id)}
                                className='category-mega-box__parent text-white   rounded-lg'
                            >
                                Lihat semua
                            </Link>
                        </div>
                    </div>
                ))}
        </div>
    </section>
  )
}

export default CategoryPilihan
