import { getTranslations, setRequestLocale } from 'next-intl/server' import { Link } from '@/i18n/navigation' import { getForumIndex, resolvePosters, type ForumRow } from '@/lib/forum' import { formatForumDate } from '@/lib/forum-format' import { PageShell } from '@/components/PageShell' export const dynamic = 'force-dynamic' export default async function ForumIndexPage({ params }: { params: Promise<{ locale: string }> }) { const { locale } = await params setRequestLocale(locale) const t = await getTranslations('Forum') const categories = await getForumIndex() // Nombres de los Ășltimos posteadores de todos los foros, en una sola consulta. const posterIds = categories.flatMap((c) => c.forums.map((f) => f.last_poster).filter(Boolean) as number[]) const posters = await resolvePosters(posterIds) function topicsLabel(n: number) { return `${n} ${n === 1 ? t('topic') : t('topics')}` } function NormalRow({ f }: { f: ForumRow }) { const iconSrc = f.type === 3 ? f.icon || '' : `/forum/forum_icons/${f.icon || 'forum_read'}.png` return (
{f.name}

{f.name}

{f.description &&

{f.description}

}

{f.post_count}

{f.topic_count}

{f.last_topic_id && (

{f.last_topic_name}

{f.last_poster != null && (

{posters.get(f.last_poster)?.name ?? `#${f.last_poster}`}

)}

{formatForumDate(f.last_time, locale)}

)}
) } function ClassTile({ f }: { f: ForumRow }) { return (

{f.name}

{topicsLabel(f.topic_count)}

) } function FlagTile({ f }: { f: ForumRow }) { return (
{f.name}

{f.name}

{topicsLabel(f.topic_count)}

) } return (
{categories.length === 0 ? (

{t('noForums')}

) : ( categories.map((cat) => { const tiles = cat.forums.filter((f) => f.type === 1 || f.type === 2) const rows = cat.forums.filter((f) => f.type !== 1 && f.type !== 2) return (
{cat.name}
{tiles.length > 0 && (
{tiles.map((f) => (f.type === 1 ? : ))}
)}
{rows.map((f) => ( ))}
) }) )}
) }