import { getDictionary } from "@/dictionaries/get-dictionary"
import NewsClient from "./NewsClient"
import { prisma } from "@/lib/prisma"

export async function generateMetadata({ params }: { params: Promise<{ lang: string }> }) {
  const { lang } = await params
  const dict = await getDictionary(lang as 'en' | 'tr')
  return {
    title: `${dict.news_page.title} - Ayris Apart`,
    description: dict.news_page.excerpt,
  }
}

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

  // Fetch posts from database based on the selected language
  const posts = await prisma.post.findMany({
    where: {
      lang: lang,
      published: true
    },
    orderBy: {
      createdAt: 'desc'
    }
  })

  return <NewsClient lang={lang} dict={dict} posts={posts} />
}
