"use client"; import Link from "next/link"; import { Item, ItemContent, ItemDescription, ItemHeader, ItemMedia, ItemTitle, } from "@/components/ui/item"; import { CapacityBar } from "@/components/frontend/storage/CapacityBar"; import { calculateStoredMass, calculateUtilization, getCategoryLabel, getFunctionTypeLabel, getGridSlots, getResourceCount, } from "@/lib/logistics"; import { installedModuleEffects } from "@/lib/base/modules"; import { Faction, GameStructure, Structure } from "@/payload-types"; import { BoxIcon, Building2Icon, ChevronRightIcon, Grid3x3Icon, MapPinIcon } from "lucide-react"; interface StructureCardProps { structure: GameStructure & { type: Structure; faction?: Faction | null; }; } export function StructureCard({ structure }: StructureCardProps) { const structureType = structure.type; const storedResources = structure.storedResources ?? []; const currentMass = calculateStoredMass(storedResources); const moduleEffects = installedModuleEffects( structureType, (structure.installedModules ?? []).map((entry) => entry.name), ); const utilization = calculateUtilization( structureType, storedResources, moduleEffects.capacityMass, ); const resourceCount = getResourceCount(storedResources); const gridSlots = getGridSlots(structureType, moduleEffects.storageSlots); const functionLabel = getFunctionTypeLabel(structureType.functionType); return (
{structure.name} {structureType.name}
{structure.faction && typeof structure.faction === "object" && ( {structure.faction.name} )} {getCategoryLabel(structureType.category)}
{resourceCount} resource{resourceCount !== 1 ? "s" : ""} {gridSlots !== null && ( {structureType.xSize}×{structureType.ySize} grid )} {functionLabel && {functionLabel}}
{structure.coordinates && ( {structure.coordinates[0].toFixed(1)}, {structure.coordinates[1].toFixed(1)} )}
{resourceCount === 0 ? "Empty: no resources stored." : `${resourceCount} resource type${resourceCount !== 1 ? "s" : ""} stored`} View details
); }