// /app/products/[slug]/page.jsx
import products from "@/lib/data/products.json";
import {notFound} from "next/navigation";
import ProductDetailClient from "@/components/ProductDetailClient";

export default async function ProductDetail({params}) {
  // Await the params before using their properties
  const {slug} = await Promise.resolve(params);
  const product = products.find((item) => item.slug === slug);
  if (!product) return notFound();

  return <ProductDetailClient product={product} />;
}

// This function is required when using export mode for dynamic routes.
export async function generateStaticParams() {
  return products.map((product) => ({
    slug: product.slug,
  }));
}
