import type { Metadata } from "next";
import { notFound } from "next/navigation";
import { PAGE_RENDERERS } from "@/app/(site)/_components/pages/renderers";
import { PreviewFrame } from "./PreviewFrame";
import { ArticlePreviewFrame } from "./ArticlePreviewFrame";
import { ProductPreviewFrame } from "./ProductPreviewFrame";

/**
 * The admin's live preview of an inner page, a service (key "service"), a product
 * (key "product") or an article (key "article"), loaded in an iframe by the editor. It renders nothing on its own:
 * the editor posts the content (drafts and unsaved edits) and this page shows it with
 * the website's own components and CSS.
 */
export const metadata: Metadata = {
  title: "Preview — Unionists Group",
  robots: { index: false, follow: false },
};

export function generateStaticParams() {
  return [...Object.keys(PAGE_RENDERERS), "product", "article"].map((key) => ({ key }));
}

export default async function Page({ params }: { params: Promise<{ key: string }> }) {
  const { key } = await params;
  if (key === "product") return <ProductPreviewFrame />;
  if (key === "article") return <ArticlePreviewFrame />;
  if (!(key in PAGE_RENDERERS)) notFound();
  return <PreviewFrame pageKey={key} />;
}
