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 { PageShell } from '@/components/PageShell'
import { ServiceBox } from '@/components/ServiceBox'
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 (
    <PageShell title={t('gold.title')}>
      <ServiceBox>
        <GoldForm characters={chars.map((c) => c.name)} options={options} />
      </ServiceBox>
    </PageShell>
  )
}
