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

export const dynamic = 'force-dynamic'

export default async function AdminPage({ 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 items: { href: string; label: string; icon: string }[] = [
    { href: '/admin/news', label: t('manageNews'), icon: '📰' },
    { href: '/admin/prices', label: t('managePrices'), icon: '💲' },
    { href: '/admin/votes', label: t('manageVotes'), icon: '🗳️' },
    { href: '/admin/gold', label: t('manageGold'), icon: '🪙' },
    { href: '/admin/users', label: t('manageUsers'), icon: '👤' },
    { href: '/admin/recruit', label: t('manageRecruit'), icon: '🎁' },
  ]

  return (
    <main className="mx-auto max-w-3xl px-4 py-8">
      <h1 className="mb-6 text-2xl font-bold text-amber-500">{t('title')}</h1>
      <div className="grid gap-3 sm:grid-cols-2">
        {items.map((it) => (
          <Link
            key={it.href}
            href={it.href}
            className="flex items-center gap-3 rounded-xl border border-nw-border/70 bg-nw-panel/80 p-4 shadow-lg shadow-black/30 backdrop-blur transition hover:border-nw-gold/60 hover:bg-nw-panel-2/70"
          >
            <span className="text-2xl" aria-hidden>{it.icon}</span>
            <span className="font-semibold text-nw-text">{it.label}</span>
            <span className="ml-auto text-nw-gold-light" aria-hidden>→</span>
          </Link>
        ))}
      </div>
    </main>
  )
}
