import { getTranslations, setRequestLocale } from 'next-intl/server'
import { redirect } from '@/i18n/navigation'
import { getSession } from '@/lib/session'
import { isAdmin } from '@/lib/admin'
import { listCategoriesWithForums } from '@/lib/admin-forum'
import { AdminForumManager } from '@/components/AdminForumManager'

export const dynamic = 'force-dynamic'

export default async function AdminForumPage({ params }: { params: Promise<{ locale: string }> }) {
  const { locale } = await params
  setRequestLocale(locale)
  const t = await getTranslations('Admin')
  const session = await getSession()
  if (!session.bnetId) redirect({ href: '/login', locale })
  if (!(await isAdmin(session))) redirect({ href: '/', locale })
  const groups = await listCategoriesWithForums()
  return (
    <main className="mx-auto max-w-3xl px-4 py-8">
      <h1 className="mb-6 text-2xl font-bold text-amber-500">{t('forum')}</h1>
      <AdminForumManager initial={groups} />
    </main>
  )
}
