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

export const dynamic = 'force-dynamic'

export default async function AccountPage({ params }: { params: Promise<{ locale: string }> }) {
  const { locale } = await params
  setRequestLocale(locale)
  const t = await getTranslations('Account')

  const session = await getSession()
  if (!session.bnetId) redirect({ href: '/login', locale })
  if (!session.username) redirect({ href: '/select-account', locale })

  return (
    <main className="mx-auto max-w-2xl px-4 py-8">
      <h1 className="mb-6 text-2xl font-bold text-amber-500">{t('title')}</h1>
      <div className="space-y-2 rounded-lg border border-amber-900/60 bg-[#241812] p-4 text-sm">
        <p>
          {t('bnetAccount')}: <span className="text-amber-400">{session.bnetEmail}</span>
        </p>
        <p>
          {t('gameAccount')}: <span className="text-amber-400">{session.username}</span>
        </p>
      </div>
      <div className="mt-6">
        <LogoutButton />
      </div>
    </main>
  )
}
