import { getTranslations } from "next-intl/server"; import Link from "next/link"; import { notFound } from "next/navigation"; import { ContentCard, EmptyState } from "@/components/public/ui"; import { prisma } from "@/lib/prisma"; import { siteSettings } from "@/lib/services/site-settings"; export const revalidate = 300; type RareRow = { id: bigint; name: string; creditValue: string | null; currencyValue: string | null; currencyType: string; furnitureIcon: string; itemId: number | null; }; type CurrencyTranslator = (key: string) => string; function prettyCurrency(type: string, t: CurrencyTranslator): string { switch (type) { case "0": case "duckets": return t("duckets"); case "5": case "diamonds": return t("diamonds"); case "-1": case "credits": return t("credits"); default: return type.charAt(0).toUpperCase() + type.slice(1); } } export default async function RareCategoryPage({ params, }: { params: Promise<{ category: string }>; }) { const t = await getTranslations("pages.rareCategory"); const { category } = await params; let categoryId: bigint; try { categoryId = BigInt(category); } catch { notFound(); } let cat: { id: bigint; name: string; badge: string } | null = null; try { cat = await prisma.websiteRareValueCategories.findUnique({ where: { id: categoryId! }, select: { id: true, name: true, badge: true }, }); } catch { cat = null; } if (!cat) notFound(); let rares: RareRow[] = []; try { rares = await prisma.websiteRareValues.findMany({ where: { categoryId: categoryId! }, orderBy: { name: "asc" }, select: { id: true, name: true, creditValue: true, currencyValue: true, currencyType: true, furnitureIcon: true, itemId: true, }, }); } catch { rares = []; } const [iconsBase, badgesBase] = await Promise.all([ siteSettings.get("furniture_icons_path", ""), siteSettings.get("badges_path", ""), ]); const iconBase = iconsBase ?? ""; const badgeBase = badgesBase ?? ""; const badgeSrc = badgeBase && cat.badge ? `${badgeBase}/${cat.badge}.gif` : ""; return (
{badgeSrc ? ( // eslint-disable-next-line @next/next/no-img-element {`${cat.name} ) : null} {cat.name} } subtitle={t("rareCount", { count: rares.length })} action={ {t("allRares")} } padded={rares.length === 0} > {rares.length === 0 ? ( {t("empty")} ) : (
{rares.map((r) => { const iconSrc = iconBase && r.furnitureIcon ? `${iconBase}/${r.furnitureIcon}` : ""; return ( ); })}
{t("colRare")} {t("colCredits")} {t("colCurrency")}
{iconSrc ? ( // eslint-disable-next-line @next/next/no-img-element ) : ( )} {r.name} {r.creditValue && r.creditValue !== "" ? ( t("creditsValue", { value: r.creditValue }) ) : ( — )} {r.currencyValue && r.currencyValue !== "" ? ( `${r.currencyValue} ${prettyCurrency(r.currencyType, t)}` ) : ( — )}
)}
); }