import type { Metadata } from 'next' import { setRequestLocale, getTranslations } from 'next-intl/server' import { redirect } from '@/i18n/navigation' import { getSession } from '@/lib/session' import { getPointsHistory, getPointsBalances, type PointsMovement } from '@/lib/points-history' import { PageShell } from '@/components/PageShell' import { ServiceBox } from '@/components/ServiceBox' export const dynamic = 'force-dynamic' export const metadata: Metadata = { title: 'Historial de PD y PV' } /** Fecha en formato DD-MM-YYYY HH:MM. */ function fmt(d: Date): string { const p = (n: number) => String(n).padStart(2, '0') return `${p(d.getDate())}-${p(d.getMonth() + 1)}-${d.getFullYear()} ${p(d.getHours())}:${p(d.getMinutes())}` } function methodClass(method: PointsMovement['method']): string { if (method === 'SumUp') return 'green-info' if (method === 'Stripe') return 'purple-info' return 'second-brown' } export default async function PointsHistoryPage({ params }: { params: Promise<{ locale: string }> }) { const { locale } = await params setRequestLocale(locale) const t = await getTranslations('History') const session = await getSession() if (!session.bnetId) redirect({ href: '/login', locale }) if (!session.username) redirect({ href: '/select-account', locale }) const [movements, balances] = await Promise.all([ getPointsHistory(session.accountId!), getPointsBalances(session.accountId!), ]) return (

{t('points.intro1')}

{t('points.intro2')}

{t('points.intro3')}


{t('points.boxTitle')}

{t('points.currentBalance')} {balances.dp} PD ·{' '} {balances.pv} PV


{movements.length === 0 ? (
{t('points.noMovements')}
) : ( {movements.map((m, i) => ( ))}
{t('points.thDate')} {t('points.thConcept')} {t('points.thMethod')} PD PV {t('points.thAmount')} {t('points.thStatus')}
{fmt(m.date)} {m.concept} {m.method} {m.pd != null ? `+${m.pd}` : '—'} {m.pv != null ? `+${m.pv}` : '—'} {m.amount != null ? `${m.amount.toFixed(2)} €` : '—'} {m.status}
)}
) }