import { getPublishedPageBySlug } from "@cms/db"
import { notFound } from "next/navigation"

import { PublicPageView } from "@/components/public-page-view"

export const dynamic = "force-dynamic"

type PageProps = {
  params: Promise<{ slug: string }>
}

export default async function CmsPageRoute({ params }: PageProps) {
  const { slug } = await params
  const page = await getPublishedPageBySlug(slug)

  if (!page) {
    notFound()
  }

  return <PublicPageView page={page} />
}
