import React from "react";
import ProductsSection from "@/features/category-details/ui/products-section";
import MyPagionation from "@/shared/ui/my-pagionation";
import { getProducts } from "@/shared/api/productSvc";

export const dynamic = "force-dynamic";

type PageProps = {
  params: {
    categoryId: number;
  };
  searchParams: { page?: string };
};

const Page = async ({ params, searchParams }: Readonly<PageProps>) => {
  const { page } = await searchParams;

  const { categoryId } = await params;
  const { data: products } = await getProducts({
    categoryId,
    currentPage: Number(page),
  });

  return (
    <div className={"section-wrapper"}>
      <div className={"section-wrapper"}>
        <ProductsSection products={products.data} />
      </div>
      <MyPagionation
        currentPage={Number(page)}
        totalPages={products.pagination.total}
      />
    </div>
  );
};
export default Page;
