import config from "@payload-config"; import { getPayload } from "payload"; import { notFound } from "next/navigation"; import Link from "next/link"; import type { Asset, Structure } from "@/payload-types"; import { RichText } from "@payloadcms/richtext-lexical/react"; import { convertLexicalToPlaintext } from "@payloadcms/richtext-lexical/plaintext"; import { ArrowLeftIcon, BoxIcon, Building2Icon, CoinsIcon, Grid3x3Icon, LayersIcon, RotateCcwIcon, ScaleIcon, TagIcon, WeightIcon, } from "lucide-react"; import { Item, ItemContent, ItemDescription, ItemHeader, ItemMedia, ItemTitle, } from "@/components/ui/item"; interface ResourceDetailPageProps { params: Promise<{ id: string }>; } const rarityColors: Record = { common: "bg-muted text-muted-foreground", uncommon: "bg-green-500/20 text-green-400", rare: "bg-blue-500/20 text-blue-400", epic: "bg-purple-500/20 text-purple-400", legendary: "bg-amber-500/20 text-amber-400", exotic: "bg-pink-500/20 text-pink-400", unique: "bg-red-500/20 text-red-400", }; const typeColors: Record = { physical: "bg-muted text-muted-foreground", fluid: "bg-blue-500/20 text-blue-400", energy: "bg-amber-500/20 text-amber-400", abstract: "bg-purple-500/20 text-purple-400", }; export default async function ResourceDetailPage({ params }: ResourceDetailPageProps) { const { id } = await params; const payload = await getPayload({ config }); const resource = await payload .findByID({ collection: "resources", id: Number(id), depth: 2, }) .catch(() => null); if (!resource) { notFound(); } const [producersRes, autoGenRes, craftingRes] = await Promise.all([ payload .find({ collection: "structures", where: { "canProduce.value": { equals: resource.id }, }, limit: 50, depth: 1, }) .catch(() => ({ docs: [] })), payload .find({ collection: "structures", where: { "autoGeneratedResources.resource": { equals: resource.id }, }, limit: 50, depth: 1, }) .catch(() => ({ docs: [] })), payload .find({ collection: "assets", where: { "crafting.craftingData.inputs.resource": { equals: resource.id }, }, limit: 50, depth: 1, }) .catch(() => ({ docs: [] })), ]); const producers = producersRes.docs as unknown as Structure[]; const autoGenStructures = autoGenRes.docs as unknown as Structure[]; const craftingAssets = craftingRes.docs as unknown as Asset[]; const allRelatedStructures = [ ...producers, ...autoGenStructures.filter((s) => !producers.some((p) => p.id === s.id)), ]; return (
Back to Resources
{resource.color ? (
) : ( )}

{resource.name}

{resource.type} {resource.rarity}
{resource.description && ( Description )}
Base Value {resource.baseValue.toLocaleString()} Unit of Measure {resource.unitOfMeasure} Mass Per Unit {resource.massPerUnit.toLocaleString()} kg Stack Size {resource.stackSize ?? 1} Grid {resource.gridWidth}×{resource.gridHeight} Stackable {resource.stackable ? "Yes" : "No"} Rotatable {resource.rotatable ? "Yes" : "No"} Tradeable {resource.tradeable ? "Yes" : "No"}
{allRelatedStructures.length > 0 && (

Related Structures

{allRelatedStructures.map((structure) => (
{structure.name}
{convertLexicalToPlaintext({ data: structure.description }).slice(0, 120)}
))}
)} {craftingAssets.length > 0 && (

Used in Crafting

{craftingAssets.map((asset) => ( {asset.name} ))}
)}
); }