import { getDictionary } from "@/dictionaries/get-dictionary"
import NewsDetailClient from "./NewsDetailClient"
import { prisma } from "@/lib/prisma"
import { notFound } from "next/navigation"

export async function generateMetadata({ params }: { params: Promise<{ lang: string, slug: string }> }) {
  const { lang, slug } = await params
  
  const post = await prisma.post.findUnique({
    where: { slug }
  })

  if (!post) return { title: 'Post Not Found' }

  return {
    title: `${post.title} - Ayris Apart`,
    description: post.excerpt,
  }
}

export default async function NewsDetailPage({ params }: { params: Promise<{ lang: string, slug: string }> }) {
  const { lang, slug } = await params
  const dict = await getDictionary(lang as 'en' | 'tr')

  const post = await prisma.post.findUnique({
    where: { slug }
  })

  if (!post) notFound()

  return <NewsDetailClient lang={lang} dict={dict} post={post} />
}
