'use client';
import Empty from "@/components/ui/empty";
import { useGetAIUserGifts } from "@/hooks/aiUser";
import { formatNumberToKMB } from "@/lib/utils";
import Image from "next/image";

export function GiftGrid({ userId }: { userId: string }) {
  const { data } = useGetAIUserGifts({ aiId: Number(userId), page: { pn: 1, ps: 100 } });
  const { datas } = data || {};

  if (datas && !datas.length) {
    return (
      <div className="bg-[#352e3e] flex flex-col gap-4 items-start justify-start p-6 rounded-2xl w-full">
        <h3 className="font-['Poppins'] font-semibold text-[20px] leading-[24px] text-white">
          Gifts
        </h3>

        <div className="py-20 w-full">
          <Empty title="No gifts yet" />
        </div>
      </div>
    )
  }

  return (
    <div className="bg-[#352e3e] flex flex-col gap-4 items-start justify-start p-6 rounded-2xl w-full">
      <h3 className="font-['Poppins'] font-semibold text-[20px] leading-[24px] text-white">
        Gifts
      </h3>
      
      <div className="w-full grid sm:grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 2xl:grid-cols-6 gap-4">
        {datas?.map((gift) => (
          <div key={gift.id} className="flex flex-col gap-1 items-start justify-start">
            <div className="bg-surface-nest-normal flex items-center justify-center rounded-sm w-full pb-[100%] relative">
              <div className="absolute inset-0 flex items-center justify-center p-4">
                <Image src={gift.icon ?? ''} alt={gift.name ?? ''} width={100} height={100} className="object-cover" />
              </div>
            </div>
            <div className="text-center w-full txt-label-m text-txt-primary-normal">
              {gift.name} X{formatNumberToKMB(gift.getNum ?? 0)}
            </div>
          </div>
        ))}
      </div>
    </div>
  );
} 