import DonutChart, {
  type DonutChartProps,
} from '@design-system/Charts/DonutChart';
import { Stack } from '@mui/material';

import { type PieChartProps } from './types';

const PieChart = ({
  values,
  colors,
  labels,
  legend = 'none',
}: PieChartProps) => {
  const props: DonutChartProps = {
    type: 'doughnut',
    data: {
      labels,
      datasets: [
        {
          data: values,
          backgroundColor: colors,
          borderColor: colors,
          borderRadius: 4,
          borderWidth: 0,
        },
      ],
    },
    options: {
      maintainAspectRatio: false,
      spacing: 2,
      plugins: {
        legend: {
          display: legend !== 'none',
          position: legend === 'none' ? 'top' : legend,
        },
      },
    },
  };

  return (
    <Stack className="PieChart-root">
      <DonutChart {...props} />
    </Stack>
  );
};

export default PieChart;
