54 lines
1.8 KiB
TypeScript
54 lines
1.8 KiB
TypeScript
"use client";
|
|
|
|
import { Progress } from "@/components/ui/progress";
|
|
import { cn } from "@/lib/utils";
|
|
|
|
interface CapacityBarProps {
|
|
utilization: number | null;
|
|
currentMass: number;
|
|
maxMass: number | null;
|
|
className?: string;
|
|
}
|
|
|
|
function getUtilizationColor(utilization: number): string {
|
|
if (utilization > 85) return "text-red-400";
|
|
if (utilization > 60) return "text-yellow-400";
|
|
return "text-green-400";
|
|
}
|
|
|
|
function getProgressColor(utilization: number): string {
|
|
if (utilization > 85) return "[&>div]:bg-red-500";
|
|
if (utilization > 60) return "[&>div]:bg-yellow-500";
|
|
return "[&>div]:bg-green-500";
|
|
}
|
|
|
|
export function CapacityBar({ utilization, currentMass, maxMass, className }: CapacityBarProps) {
|
|
if (utilization === null || maxMass === null) {
|
|
return (
|
|
<div className={cn("flex flex-col gap-1", className)}>
|
|
<div className="flex items-center justify-between text-xs">
|
|
<span className="text-muted-foreground">Mass stored</span>
|
|
<span className="text-muted-foreground">{currentMass.toLocaleString()} kg</span>
|
|
</div>
|
|
<Progress value={0} className="h-1.5" />
|
|
</div>
|
|
);
|
|
}
|
|
|
|
const colorClass = getUtilizationColor(utilization);
|
|
const progressClass = getProgressColor(utilization);
|
|
|
|
return (
|
|
<div className={cn("flex flex-col gap-1", className)}>
|
|
<div className="flex items-center justify-between text-xs">
|
|
<span className="text-muted-foreground">Capacity</span>
|
|
<span className={cn("font-medium", colorClass)}>{Math.round(utilization)}%</span>
|
|
</div>
|
|
<Progress value={utilization} className={cn("h-1.5", progressClass)} />
|
|
<div className="flex items-center justify-between text-xs text-muted-foreground">
|
|
<span>{currentMass.toLocaleString()} kg</span>
|
|
<span>{maxMass.toLocaleString()} kg</span>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|