285 lines
10 KiB
TypeScript
285 lines
10 KiB
TypeScript
import config from "@payload-config";
|
|
import { getPayload } from "payload";
|
|
import { notFound } from "next/navigation";
|
|
import Link from "next/link";
|
|
import type { GameStructure, GameVehicle, Resource, Structure, Vehicle } from "@/payload-types";
|
|
import {
|
|
ArrowLeftIcon,
|
|
FuelIcon,
|
|
HeartIcon,
|
|
MapPinIcon,
|
|
ShieldIcon,
|
|
TruckIcon,
|
|
} from "lucide-react";
|
|
import {
|
|
Item,
|
|
ItemContent,
|
|
ItemDescription,
|
|
ItemHeader,
|
|
ItemMedia,
|
|
ItemTitle,
|
|
} from "@/components/ui/item";
|
|
|
|
interface GameVehicleDetailPageProps {
|
|
params: Promise<{ id: string }>;
|
|
}
|
|
|
|
const statusColors: Record<string, string> = {
|
|
idle: "bg-emerald-500/20 text-emerald-400",
|
|
assigned: "bg-blue-500/20 text-blue-400",
|
|
in_transit: "bg-amber-500/20 text-amber-400",
|
|
damaged: "bg-red-500/20 text-red-400",
|
|
destroyed: "bg-red-500/20 text-red-400",
|
|
};
|
|
|
|
export default async function GameVehicleDetailPage({ params }: GameVehicleDetailPageProps) {
|
|
const { id } = await params;
|
|
const payload = await getPayload({ config });
|
|
|
|
const vehicle = await payload
|
|
.findByID({
|
|
collection: "game-vehicles",
|
|
id: Number(id),
|
|
depth: 2,
|
|
})
|
|
.catch(() => null);
|
|
|
|
if (!vehicle) {
|
|
notFound();
|
|
}
|
|
|
|
const vehicleData = vehicle as unknown as GameVehicle & {
|
|
type: Vehicle;
|
|
};
|
|
const vehicleType = typeof vehicleData.type === "object" ? vehicleData.type : null;
|
|
const deployedAt =
|
|
typeof vehicleData.deployedAt === "object" && vehicleData.deployedAt !== null
|
|
? (vehicleData.deployedAt as GameStructure & { type: Structure })
|
|
: null;
|
|
const faction =
|
|
typeof vehicleData.faction === "object" && vehicleData.faction !== null
|
|
? vehicleData.faction
|
|
: null;
|
|
|
|
const fuelPercent = vehicleType?.fuel?.fuelCapacity
|
|
? (vehicleData.currentFuel / vehicleType.fuel.fuelCapacity) * 100
|
|
: 0;
|
|
|
|
const storedResources = vehicleData.storedResources ?? [];
|
|
const resourceCount = storedResources.length;
|
|
|
|
return (
|
|
<div className="p-5 flex flex-col gap-6 max-w-7xl">
|
|
<Link
|
|
href="/logistics/garage"
|
|
className="py-1 text-sm text-muted-foreground hover:text-primary transition-colors flex items-center gap-1 w-fit"
|
|
>
|
|
<ArrowLeftIcon className="size-3" />
|
|
Back to Garage
|
|
</Link>
|
|
|
|
<div className="flex items-start justify-between gap-4">
|
|
<div className="flex flex-col gap-1">
|
|
<div className="flex items-center gap-2">
|
|
<TruckIcon className="size-5 text-muted-foreground" />
|
|
<h1 className="text-lg font-semibold">{vehicleData.name}</h1>
|
|
</div>
|
|
<div className="flex items-center gap-2">
|
|
<span
|
|
className={`text-[10px] font-semibold uppercase tracking-wider px-1.5 py-0.5 rounded ${statusColors[vehicleData.status] ?? "bg-muted text-muted-foreground"}`}
|
|
>
|
|
{vehicleData.status === "in_transit"
|
|
? "In Transit"
|
|
: vehicleData.status.charAt(0).toUpperCase() + vehicleData.status.slice(1)}
|
|
</span>
|
|
<span className="text-xs text-muted-foreground">
|
|
{vehicleType?.name ?? "Unknown type"}
|
|
</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div className="grid grid-cols-2 md:grid-cols-4 gap-3">
|
|
<Item variant="muted" size="sm">
|
|
<ItemMedia variant="icon">
|
|
<FuelIcon />
|
|
</ItemMedia>
|
|
<ItemContent>
|
|
<ItemTitle>Fuel</ItemTitle>
|
|
<ItemDescription>
|
|
{vehicleData.currentFuel?.toFixed(1)} / {vehicleType?.fuel?.fuelCapacity ?? "?"}
|
|
</ItemDescription>
|
|
</ItemContent>
|
|
</Item>
|
|
<Item variant="muted" size="sm">
|
|
<ItemMedia variant="icon">
|
|
<HeartIcon />
|
|
</ItemMedia>
|
|
<ItemContent>
|
|
<ItemTitle>Health</ItemTitle>
|
|
<ItemDescription>{vehicleData.currentHealth}</ItemDescription>
|
|
</ItemContent>
|
|
</Item>
|
|
<Item variant="muted" size="sm">
|
|
<ItemMedia variant="icon">
|
|
<MapPinIcon />
|
|
</ItemMedia>
|
|
<ItemContent>
|
|
<ItemTitle>Location</ItemTitle>
|
|
<ItemDescription>{deployedAt?.name ?? "In transit"}</ItemDescription>
|
|
</ItemContent>
|
|
</Item>
|
|
<Item variant="muted" size="sm">
|
|
<ItemMedia variant="icon">
|
|
<ShieldIcon />
|
|
</ItemMedia>
|
|
<ItemContent>
|
|
<ItemTitle>Faction</ItemTitle>
|
|
<ItemDescription>{faction?.name ?? "Unassigned"}</ItemDescription>
|
|
</ItemContent>
|
|
</Item>
|
|
</div>
|
|
|
|
<div className="grid grid-cols-1 xl:grid-cols-3 gap-6">
|
|
<div className="xl:col-span-2 flex flex-col gap-6">
|
|
{/* Fuel Gauge */}
|
|
<Item variant="outline">
|
|
<ItemHeader>
|
|
<div className="flex items-center gap-2">
|
|
<FuelIcon className="size-4 text-muted-foreground" />
|
|
<ItemTitle>Fuel Tank</ItemTitle>
|
|
</div>
|
|
</ItemHeader>
|
|
<ItemContent className="flex flex-col gap-3">
|
|
<div className="flex items-center gap-2">
|
|
<div className="flex-1 h-3 bg-border rounded-full overflow-hidden">
|
|
<div
|
|
className={`h-full rounded-full transition-all ${
|
|
fuelPercent > 20 ? "bg-green-500" : "bg-red-500"
|
|
}`}
|
|
style={{
|
|
width: `${Math.min(100, fuelPercent)}%`,
|
|
}}
|
|
/>
|
|
</div>
|
|
<span className="text-sm font-mono font-semibold">{fuelPercent.toFixed(0)}%</span>
|
|
</div>
|
|
<div className="flex justify-between text-xs text-muted-foreground">
|
|
<span>{vehicleData.currentFuel?.toFixed(1)} units remaining</span>
|
|
<span>Capacity: {vehicleType?.fuel?.fuelCapacity ?? "?"} units</span>
|
|
</div>
|
|
{vehicleType?.fuel?.fuelType && typeof vehicleType.fuel.fuelType === "object" && (
|
|
<div className="text-xs text-muted-foreground">
|
|
Fuel type: {vehicleType.fuel.fuelType.name} · Consumption rate:{" "}
|
|
{vehicleType.fuel.fuelConsumptionRate}/unit
|
|
</div>
|
|
)}
|
|
</ItemContent>
|
|
</Item>
|
|
|
|
{/* Cargo */}
|
|
<Item variant="outline">
|
|
<ItemHeader>
|
|
<ItemTitle>Cargo</ItemTitle>
|
|
<span className="text-xs text-muted-foreground">
|
|
{resourceCount} item type{resourceCount !== 1 ? "s" : ""}
|
|
</span>
|
|
</ItemHeader>
|
|
<ItemContent>
|
|
{storedResources.length > 0 ? (
|
|
<div className="border border-border rounded-lg overflow-hidden">
|
|
<table className="w-full text-sm">
|
|
<thead>
|
|
<tr className="bg-muted/50 border-b border-border">
|
|
<th className="text-left px-4 py-2.5 font-semibold uppercase text-xs tracking-wider text-muted-foreground">
|
|
Resource
|
|
</th>
|
|
<th className="text-right px-4 py-2.5 font-semibold uppercase text-xs tracking-wider text-muted-foreground">
|
|
Amount
|
|
</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
{storedResources.map((entry, index) => {
|
|
const resource =
|
|
typeof entry.resource === "object" ? (entry.resource as Resource) : null;
|
|
return (
|
|
<tr key={index} className="border-b border-border/50">
|
|
<td className="px-4 py-2 font-medium">
|
|
{resource?.name ?? `Resource #${entry.resource}`}
|
|
</td>
|
|
<td className="px-4 py-2 text-right font-mono">
|
|
{entry.amount?.toLocaleString()}
|
|
</td>
|
|
</tr>
|
|
);
|
|
})}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
) : (
|
|
<p className="text-sm text-muted-foreground italic">Vehicle cargo is empty.</p>
|
|
)}
|
|
</ItemContent>
|
|
</Item>
|
|
</div>
|
|
|
|
{/* Sidebar */}
|
|
<div className="flex flex-col gap-4">
|
|
{/* Vehicle Type Info */}
|
|
<Item variant="outline">
|
|
<ItemHeader>
|
|
<ItemTitle>Vehicle Type</ItemTitle>
|
|
</ItemHeader>
|
|
<ItemContent>
|
|
<div className="flex flex-col gap-2 text-sm">
|
|
<div>
|
|
<p className="font-semibold">{vehicleType?.name ?? "Unknown"}</p>
|
|
{vehicleType?.classname && (
|
|
<p className="text-xs text-muted-foreground font-mono">
|
|
{vehicleType.classname}
|
|
</p>
|
|
)}
|
|
</div>
|
|
{vehicleType?.category && vehicleType.category.length > 0 && (
|
|
<div className="flex flex-wrap gap-1">
|
|
{vehicleType.category.map((cat) => (
|
|
<span
|
|
key={cat}
|
|
className="text-[10px] font-semibold uppercase tracking-wider px-1.5 py-0.5 rounded bg-muted"
|
|
>
|
|
{cat}
|
|
</span>
|
|
))}
|
|
</div>
|
|
)}
|
|
</div>
|
|
</ItemContent>
|
|
</Item>
|
|
|
|
{/* Location */}
|
|
{deployedAt && (
|
|
<Link href={`/logistics/structures/${deployedAt.id}`}>
|
|
<Item
|
|
variant="outline"
|
|
className="cursor-pointer group transition-all duration-200 hover:scale-[1.01]"
|
|
>
|
|
<ItemHeader>
|
|
<div className="flex items-center gap-2">
|
|
<MapPinIcon className="size-4 text-muted-foreground" />
|
|
<ItemTitle>Stationed At</ItemTitle>
|
|
</div>
|
|
</ItemHeader>
|
|
<ItemContent>
|
|
<p className="text-sm font-semibold group-hover:text-primary transition-colors">
|
|
{deployedAt.name}
|
|
</p>
|
|
</ItemContent>
|
|
</Item>
|
|
</Link>
|
|
)}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|