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

export const dynamic = "force-dynamic"

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

export default async function PublicNewsDetailPage({ params }: PageProps) {
  const { slug } = await params
  const post = await getPostBySlug(slug)

  if (!post || post.status !== "published") {
    notFound()
  }

  return (
    <article className="mx-auto w-full max-w-4xl space-y-4 px-6 py-16">
      <header className="space-y-2">
        <p className="text-sm uppercase tracking-[0.2em] text-neutral-500">News</p>
        <h1 className="text-4xl font-semibold tracking-tight">{post.title}</h1>
        {post.excerpt ? <p className="text-neutral-600">{post.excerpt}</p> : null}
      </header>
      <section className="prose prose-neutral max-w-none whitespace-pre-wrap rounded-xl border border-neutral-200 bg-white p-6 text-neutral-800">
        {post.body}
      </section>
    </article>
  )
}
