import { notFound } from "next/navigation";
import { readSchema } from "@/lib/schema.server";
import RenderClient from "@/components/RenderClient";

export const dynamic = "force-dynamic";

export default async function Page({
  params,
}: {
  params: Promise<{ path?: string[] }>;
}) {
  const { path } = await params;
  const segments = (path ?? []).filter(Boolean);

  // The /edit branch is handled by app/edit; this catch-all only serves view.
  if (segments[0] === "edit") return notFound();

  const route = "/" + segments.join("/");
  const lookup = route === "/" ? "/" : route.replace(/\/$/, "");

  const schema = await readSchema();
  const data = schema[lookup];
  if (!data) return notFound();

  return <RenderClient data={data} route={lookup} />;
}
