// app/review/page.tsx
import { notFound } from "next/navigation";
import Custom from "./Custom";

async function fetchFormData(id: string | null) {
  if (!id) return null;

  try {
    const response = await fetch(
      `${process.env.NEXT_PUBLIC_RENDER_LINK}/get-create-data?id=${id}`,
      {
        cache: "no-store", // Her seferinde veri çekilmesini sağlar
      }
    );
    if (!response.ok) {
      throw new Error(`HTTP error! status: ${response.status}`);
    }
    return response.json();
  } catch (error) {
    console.error("Error fetching data:", error);
    return null;
  }
}

export default async function ReviewPage({
  searchParams,
}: {
  searchParams: { id?: string };
}) {
  const { id } = searchParams;
  const formData = await fetchFormData(id || "");

  if (!formData) {
    notFound(); // Sayfa bulunamadı
  }

  return <Custom id={id || ""} />;
}
