'use client';
import type { HTMLAttributes } from 'react';
import { Bar, BarChart, ResponsiveContainer, Tooltip, XAxis, YAxis } from 'recharts';
import { formatMonth } from '@documenso/lib/client-only/format-month';
export type BarMetricProps> = HTMLAttributes & {
data: T;
metricKey: keyof T[string];
title: string;
label: string;
chartHeight?: number;
extraInfo?: JSX.Element;
};
export const BarMetric = >>({
className,
data,
metricKey,
title,
label,
chartHeight = 400,
extraInfo,
...props
}: BarMetricProps) => {
const formattedData = Object.keys(data)
.map((key) => ({
month: formatMonth(key),
[metricKey]: data[key][metricKey],
}))
.reverse();
return (
{title}
{extraInfo}
[Number(value), label]}
cursor={{ fill: 'hsl(var(--primary) / 10%)' }}
/>
);
};