import { getTranslations, setRequestLocale } from 'next-intl/server'
import { redirect } from '@/i18n/navigation'
import { getSession } from '@/lib/session'
import { getGameCharacters } from '@/lib/characters'
import { getGoldOptions } from '@/lib/prices'
import { GoldForm } from '@/components/GoldForm'

export const dynamic = 'force-dynamic'

export default async function GoldPage({ params }: { params: Promise<{ locale: string }> }) {
  const { locale } = await params
  setRequestLocale(locale)
  const t = await getTranslations('Paid')
  const session = await getSession()
  if (!session.bnetId) redirect({ href: '/login', locale })
  if (!session.username) redirect({ href: '/select-account', locale })

  const [chars, options] = await Promise.all([getGameCharacters(session.accountId!), getGoldOptions()])

  return (
    <main className="mx-auto max-w-3xl px-4 py-8">
      <h1 className="mb-6 text-center text-2xl font-bold text-amber-500">{t('gold.title')}</h1>
      <GoldForm characters={chars.map((c) => c.name)} options={options} />
    </main>
  )
}
