import { notFound } from 'next/navigation'
import { getTranslations, setRequestLocale } from 'next-intl/server'
import { Link } from '@/i18n/navigation'
import {
getGuildInfo,
getGuildRoster,
getGuildRecentAchievements,
getRealmName,
getGuildAchievementOverview,
getGuildRoleBreakdown,
} from '@/lib/armory'
import { getSession } from '@/lib/session'
import { isGuildMemberByAccount } from '@/lib/armory'
import { className, classColor } from '@/lib/wow-data'
import { wowheadIcon } from '@/lib/wowhead'
import { PageShell } from '@/components/PageShell'
import { ArmoryGuildRoster } from '@/components/ArmoryGuildRoster'
import { ArmoryAchievements } from '@/components/ArmoryAchievements'
export const dynamic = 'force-dynamic'
const PAGE_SIZE = 25
export default async function GuildPage({
params,
searchParams,
}: {
params: Promise<{ locale: string; guid: string }>
searchParams: Promise<{ tab?: string }>
}) {
const { locale, guid } = await params
const { tab } = await searchParams
setRequestLocale(locale)
const t = await getTranslations('Armory')
const guildId = Number(guid)
const info = await getGuildInfo(guildId)
if (!info) notFound()
const isLogros = tab === 'logros'
const emblemHue = (info.emblem.bg * 7) % 360
return (
← {t('backToArmory')}
{/* Cabecera de hermandad */}
{info.name}
{/* reino */}
{info.guildPoints.toLocaleString(locale)}
{info.memberCount} {t('members')}
{info.createdYear > 0 && (
{t('guildFounded')} {info.createdYear}
)}
{t('guild')}
{t('guildAchievements')}
{isLogros ? (
) : (
)}
)
}
/* ---- Vista Hermandad (roster + barra lateral) ---- */
async function GuildRoster({
guildId,
locale,
info,
t,
}: {
guildId: number
locale: string
// eslint-disable-next-line @typescript-eslint/no-explicit-any
info: any
// eslint-disable-next-line @typescript-eslint/no-explicit-any
t: any
}) {
const session = await getSession()
const accountId = session.accountId ?? 0
const [roster, recent, realm, roleBreak, isMember] = await Promise.all([
getGuildRoster(guildId, { page: 1, pageSize: PAGE_SIZE, classes: [], roles: [], sort: 'rank' }),
getGuildRecentAchievements(guildId, locale, 5),
getRealmName(),
getGuildRoleBreakdown(guildId),
isGuildMemberByAccount(accountId, guildId),
])
const motdState: 'guest' | 'member' | 'nonmember' = !accountId ? 'guest' : isMember ? 'member' : 'nonmember'
const roleRows: { key: 'tank' | 'healer' | 'dps'; label: string; color: string; count: number }[] = [
{ key: 'tank', label: t('roleTank'), color: '#4a90d9', count: roleBreak.tank },
{ key: 'healer', label: t('roleHealer'), color: '#4ade5f', count: roleBreak.healer },
{ key: 'dps', label: t('roleDps'), color: '#d9534f', count: roleBreak.dps },
]
const maxRole = Math.max(1, roleBreak.tank, roleBreak.healer, roleBreak.dps)
const maxCount = Math.max(1, ...info.classBreakdown.map((c: { count: number }) => c.count))
const fmtDate = (unix: number) => {
if (!unix) return ''
const d = new Date(unix * 1000)
return Number.isNaN(d.getTime()) ? '' : d.toLocaleDateString(locale, { day: '2-digit', month: '2-digit', year: 'numeric' })
}
return (
{t('guildMembers')} · {realm}
c.class)}
labels={{
view: t('guildView'), sortRank: t('guildSortRank'), sortPoints: t('guildSortPoints'),
sortLevel: t('guildSortLevel'), sortName: t('guildSortName'), filterClass: t('guildFilterClass'),
allClasses: t('guildAllClasses'), filterRole: t('guildFilterRole'), allRoles: t('guildAllRoles'),
roleTank: t('roleTank'), roleHealer: t('roleHealer'), roleDps: t('roleDps'),
sortIlvl: t('guildSortIlvl'), ilvl: t('colIlvl'),
name: t('colName'), race: t('colRace'), class: t('colClass'), role: t('colFunction'),
level: t('colLevel'), rank: t('colRank'), points: t('guildSortPoints'),
}}
/>
)
}
/* ---- Vista Logros de hermandad (anillos por categoría) ---- */
async function GuildLogros({
guildId,
locale,
t,
}: {
guildId: number
locale: string
// eslint-disable-next-line @typescript-eslint/no-explicit-any
t: any
}) {
const overview = await getGuildAchievementOverview(guildId, null, locale)
return (
)
}