import type { Metadata } from 'next' import { setRequestLocale, getTranslations } from 'next-intl/server' import { redirect } from '@/i18n/navigation' import { getSession } from '@/lib/session' import { getSecurityHistory } from '@/lib/security-history' import { wowAccountLabel } from '@/lib/bnet' import { PageShell } from '@/components/PageShell' import { ServiceBox } from '@/components/ServiceBox' export const dynamic = 'force-dynamic' export async function generateMetadata({ params }: { params: Promise<{ locale: string }> }): Promise { const { locale } = await params const t = await getTranslations({ locale, namespace: 'History' }) return { title: t('security.pageTitle') } } /** Fecha en formato HH:MM:SS DD-MM-YYYY (como el diseño). */ function fmt(d: Date): string { const p = (n: number) => String(n).padStart(2, '0') return `${p(d.getHours())}:${p(d.getMinutes())}:${p(d.getSeconds())} ${p(d.getDate())}-${p(d.getMonth() + 1)}-${d.getFullYear()}` } /** Celda «Usuario»: cuenta de juego (WOW1) + cuenta Battle.net (email) debajo. */ function UserCell({ label, bnet }: { label: string; bnet: string }) { return ( {label} {bnet && ( <>
{bnet} )} ) } export default async function SecurityHistoryPage({ 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: '/log-in', locale }) if (!session.username) redirect({ href: '/select-account', locale }) const bnetEmail = session.bnetEmail || '' const displayUser = wowAccountLabel(session.username || '') // «15#1» → «WOW1» const { activity, realm, web } = await getSecurityHistory(session.accountId!, displayUser, bnetEmail) return (

{t('security.intro1')}

{t('security.intro2')}

{t('security.intro3')}


{t('security.activityTitle')}

{t('security.activityDesc')}


{t('security.realmTitle')}

{t.rich('security.realmDesc', { u: (c) => {c} })}


{t('security.webTitle')}

{t('security.webDesc')}

{/* Historial de actividad */}

{t('security.activityTitle')}

{activity.length === 0 ? (
{t('security.noActivity')}
) : ( {activity.map((a, i) => ( ))}
{t('security.thUser')} {t('security.thAction')} IP {t('security.thDate')}
{t(`security.action.${a.actionKey}`)} {a.ip} {fmt(a.date)}
)}
{/* Historial de conexiones (Reino) */}

{t('security.realmTitle')}

{realm.length === 0 ? (
{t('security.noConnections')}
) : ( {realm.map((c, i) => ( ))}
IP {t('security.thDate')}
{c.ip} {fmt(c.date)}
)}
{/* Historial de conexiones (Web) */}

{t('security.webTitle')}

{web.length === 0 ? (
{t('security.noConnections')}
) : ( {web.map((c, i) => ( ))}
{t('security.thUser')} {t('security.thStatus')} IP {t('security.thDate')}
{c.statusKey === 'other' ? c.statusRaw : t(`security.webStatus.${c.statusKey}`)} {c.ip} {fmt(c.date)}
)}
) }