import type React from "react";
import { Bar } from "react-chartjs-2";
import { Chart as ChartJS, CategoryScale, LinearScale, BarElement, Tooltip, Legend } from "chart.js";
import type { RepositoryStats } from "api/types/RepositoryStats";

ChartJS.register(CategoryScale, LinearScale, BarElement, Tooltip, Legend);

interface PackageCountBarChartProps {
    stats: RepositoryStats;
}

export default function PackageCountBarChart({ stats }: PackageCountBarChartProps): React.JSX.Element {
    const data = {
        labels: ["packages"],
        datasets: [
            {
                label: "archives",
                data: [stats.packages ?? 0],
            },
            {
                label: "bases",
                data: [stats.bases ?? 0],
            },
        ],
    };

    return (
        <Bar
            data={data}
            options={{
                maintainAspectRatio: false,
                responsive: true,
                scales: {
                    x: { stacked: true },
                },
            }}
        />
    );
}
