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

export const dynamic = 'force-dynamic'

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

  const orders = await getPendingOrders(session.accountId ?? 0)

  return (
    <main className="mx-auto max-w-2xl px-4 py-8">
      <h1 className="mb-2 text-2xl font-bold text-amber-500">{t('title')}</h1>
      <p className="mb-6 text-nw-muted">{t('intro')}</p>
      <BattlepayList orders={orders} />
    </main>
  )
}
