import { getTranslations, setRequestLocale } from 'next-intl/server' import { Link } from '@/i18n/navigation' import { searchCharacters, searchItems, searchGuilds } from '@/lib/armory' import { raceName, className, classColor } from '@/lib/wow-data' import { wowheadUrl, wowheadData } from '@/lib/wowhead' import { PageShell } from '@/components/PageShell' import { ArmorySearchBox } from '@/components/ArmorySearchBox' import { WowheadRefresh } from '@/components/WowheadRefresh' export const dynamic = 'force-dynamic' const TABS = ['characters', 'items', 'guilds'] as const type Tab = (typeof TABS)[number] export default async function ArmoryPage({ params, searchParams, }: { params: Promise<{ locale: string }> searchParams: Promise<{ tab?: string; q?: string }> }) { const { locale } = await params setRequestLocale(locale) const t = await getTranslations('Armory') const sp = await searchParams const tab: Tab = TABS.includes(sp.tab as Tab) ? (sp.tab as Tab) : 'characters' const q = (sp.q ?? '').trim() const hasQuery = q.length >= 3 const characters = hasQuery && tab === 'characters' ? await searchCharacters(q) : [] const items = hasQuery && tab === 'items' ? await searchItems(q, locale) : [] const guilds = hasQuery && tab === 'guilds' ? await searchGuilds(q) : [] const tabLabel: Record = { characters: t('tabCharacters'), items: t('tabItems'), guilds: t('tabGuilds'), } return (
{TABS.map((tb) => ( {tabLabel[tb]} ))}
{!hasQuery ? (

{t('searchHint')}

) : tab === 'characters' ? ( characters.length === 0 ? (

{t('noResults')}

) : (
{characters.map((c) => ( {c.name} {t('level')} {c.level} · {raceName(c.race, locale)} · {className(c.class, locale)} ))}
) ) : tab === 'items' ? ( items.length === 0 ? (

{t('noResults')}

) : (
{items.map((it) => (
{it.name} {t('itemLevel')} {it.itemLevel}
))}
) ) : guilds.length === 0 ? (

{t('noResults')}

) : (
{guilds.map((g) => ( {g.name} {g.members} {t('members')} ))}
)}
) }