import categoryService from "@/lib/services/category";
import { ProductResponse } from "@/lib/types/models";
import { cookies } from "next/headers";
import React from "react";
import SwiperComponent from "@/modules/home/components/recently-viewed-items/swiper-component";

export default async function Page() {
  const cookieStore = await cookies();
  const recent = cookieStore.get("recent")?.value;
  if (!recent) return null;
  const response: ProductResponse =
    await categoryService.fetchProductByCategory(`ids=${recent}&limit=10`);
  const data = response.success ? response?.data : [];
  if (data?.length === 0) return null;
  return (
    <div className="main-container py-[20px] relative">
      <h2 className="mobile-container text-[20px] lg:text-[32px] leading-[25.2px] lg:leading-[42.84px] text-neutral-black-87 mb-[20px] md:mb-[36px] font-semibold">
        Recently Viewed Items
      </h2>
      <SwiperComponent data={data} />
    </div>
  );
}
