import { getTranslations, setRequestLocale } from 'next-intl/server'
import { redirect } from '@/i18n/navigation'
import { getSession } from '@/lib/session'
import { getPendingOrders } from '@/lib/battlepay'
import { PageShell } from '@/components/PageShell'
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: '/log-in', locale })
  if (!session.username) redirect({ href: '/select-account', locale })

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

  return (
    <PageShell title={t('title')}>
      <div className="box-content">
        <div className="body-box-content centered">
          <p>{t('intro')}</p>
          <br />
          <BattlepayList orders={orders} />
        </div>
      </div>
    </PageShell>
  )
}
