import React from "react";
import { formatNumber } from "~/lib/utils";
interface DataItem {
label: string;
value: number;
color: string;
}
interface DashboardCustomBarChartProps {
title: string;
data: DataItem[];
loading?: boolean;
}
export function DashboardCustomBarChart({
title,
data,
loading = false,
}: DashboardCustomBarChartProps) {
if (loading) {
return (
{title}
{[1, 2, 3].map((i) => (
))}
);
}
// Calculate the maximum value for scaling
const maxValue = Math.max(...data.map((item) => item.value));
return (
{title}
{data.map((item, index) => {
const widthPercentage =
maxValue > 0 ? (item.value / maxValue) * 100 : 0;
return (
{/* Bar container */}
{/* Animated bar */}
{item.label}
{formatNumber(item.value)}
);
})}
);
}