import { useMemo, ReactNode } from "react"
// @mui material components
import Card from "@mui/material/Card"
import Icon from "@mui/material/Icon"
// ThreeD Garden components
import MDBox from "~/components/mui/MDBox"
import MDTypography from "~/components/mui/MDTypography"
// PieChart configurations
import configs from "~/components/elements/Charts/PieChart/configs"
// react-chartjs-2 components
import { Pie } from "react-chartjs-2"
import {
Chart as ChartJS,
ArcElement,
// CategoryScale,
// LinearScale,
// PointElement,
// LineElement,
// BarElement,
Title,
Tooltip,
Legend
} from "chart.js"
ChartJS.register(
ArcElement,
// CategoryScale,
// LinearScale,
// PointElement,
// LineElement,
// BarElement,
Title,
Tooltip,
Legend
)
// Declaring props types for PieChart
interface Props {
icon?: {
color?:
| "primary"
| "secondary"
| "info"
| "success"
| "warning"
| "error"
| "light"
| "dark"
component: ReactNode
}
title?: string
description?: string | ReactNode
height?: string | number
chart: {
labels: string[]
datasets: {
label: string
backgroundColors: string[]
data: number[]
}
}
[key: string]: any
}
function PieChart({
icon,
title,
description,
height,
chart,
}: Props): JSX.Element {
const { data, options } = configs(chart.labels || [], chart.datasets || {})
const renderChart = (
{title || description ? (
{icon.component && (
{icon.component}
)}
{title && {title}}
{description}
) : null}
{useMemo(
() => (
{/* options={options} */}
),
[chart, height]
)}
)
return title || description ? {renderChart} : renderChart
}
// Declaring default props for PieChart
PieChart.defaultProps = {
icon: { color: "info", component: "" },
title: "",
description: "",
height: "19.125rem",
}
export default PieChart