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

export const dynamic = 'force-dynamic'

export default async function TransferPage({ 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, price] = await Promise.all([getGameCharacters(session.accountId!), getTransferPrice()])

  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('transfer.title')}</h1>
      <TransferForm characters={chars.map((c) => c.name)} price={price} />
    </main>
  )
}
