"use client"; import Link from "next/link"; import { Item, ItemContent, ItemDescription, ItemHeader, ItemMedia, ItemTitle, } from "@/components/ui/item"; import { convertLexicalToPlaintext } from "@payloadcms/richtext-lexical/plaintext"; import { BrainIcon, ChevronRightIcon, DropletIcon, HandshakeIcon, PackageOpenIcon, ScaleIcon, ZapIcon, } from "lucide-react"; interface ResourceCardProps { resource: { id: number; name: string; codeName: string; type: "physical" | "fluid" | "energy" | "abstract"; rarity: string; baseValue: number; unitOfMeasure: string; massPerUnit: number; icon?: { url: string } | number | null; color?: string | null; tradeable?: boolean | null; description?: { root: { type: string; children: { type: any; version: number; [k: string]: unknown; }[]; direction: ("ltr" | "rtl") | null; format: "left" | "start" | "center" | "right" | "end" | "justify" | ""; indent: number; version: number; }; [k: string]: unknown; } | null; }; } const typeColors: Record = { physical: "bg-stone-500/20 text-stone-400", fluid: "bg-blue-500/20 text-blue-400", energy: "bg-amber-500/20 text-amber-400", abstract: "bg-purple-500/20 text-purple-400", }; const typeIcons: Record = { physical: , fluid: , energy: , abstract: , }; 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 rarityLabels: Record = { common: "Common", uncommon: "Uncommon", rare: "Rare", epic: "Epic", legendary: "Legendary", exotic: "Exotic", unique: "Unique", }; export function ResourceCard({ resource }: ResourceCardProps) { const icon = resource.icon && typeof resource.icon === "object" ? resource.icon : null; const description = resource.description ? convertLexicalToPlaintext({ data: resource.description }) : null; const truncatedDescription = description && description.length > 150 ? description.slice(0, 150) + "…" : description; return (
{icon ? ( {resource.name} ) : resource.color ? ( ) : ( {typeIcons[resource.type]} )} {resource.codeName} {resource.name}
{resource.type} {rarityLabels[resource.rarity] ?? resource.rarity}
{truncatedDescription && (

{truncatedDescription}

)}
{resource.baseValue.toLocaleString()} credits {resource.massPerUnit.toLocaleString()} kg/{resource.unitOfMeasure} {resource.tradeable && ( Tradeable )}
{truncatedDescription ?? `${resource.type} resource (${resource.unitOfMeasure})`} View details
); }