import { unstable_noStore } from "next/cache";
import { notFound } from "next/navigation";
import { getAllPresse, getPresseById } from "@/lib/db/presse";
import PresseDetailClient from "./PresseDetailClient";

// Toujours interroger la BDD à chaque requête (pas de cache)
export const dynamic = "force-dynamic";
export const revalidate = 0;
export const dynamicParams = true;

export async function generateStaticParams() {
  try {
    const items = await getAllPresse();
    return items.map((item) => ({ id: String(item.id) }));
  } catch {
    return [];
  }
}

export default async function PresseDetailPage({
  params,
}: {
  params: Promise<{ id: string }>;
}) {
  unstable_noStore();
  const { id } = await params;
  const parsedId = parseInt(id, 10);
  if (Number.isNaN(parsedId)) notFound();

  const item = await getPresseById(parsedId);
  if (!item) notFound();

  return <PresseDetailClient item={item} />;
}
