"use client"

import { Label, PolarRadiusAxis, RadialBar, RadialBarChart } from "recharts";

import {
  Card,
  CardContent,
  CardFooter,
  CardHeader,
  CardTitle,
} from "@/components/ui/card";
import {
  ChartConfig,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
} from "@/components/ui/chart";

export const description = "A radial chart with stacked sections";

const chartData = [{ month: "january", desktop: 96, mobile: 0, }];

const chartConfig = {
  desktop: {
    label: "Overall score",
    color: "var(--chart-2)",
  },
} satisfies ChartConfig;

export function StackChart() {
  const totalVisitors = chartData[0].desktop;

  return (
    <Card className="flex flex-col border w-[300px] h-[300px] mt-8 mb-8 mx-auto shadow-lg">
      <CardHeader className="pb-2">
        <CardTitle className="text-center">Student growth</CardTitle>
      </CardHeader>
      <CardContent className="flex flex-1 items-center justify-center p-0">
        <div className="relative w-[200px] h-[200px]">
          <ChartContainer
            config={chartConfig}
            className="w-full h-full"
          >
            <RadialBarChart
              data={chartData}
              startAngle={180}
              endAngle={0}
              innerRadius={80}
              outerRadius={130}
            >
              <ChartTooltip
                cursor={false}
                content={<ChartTooltipContent hideLabel />}
              />
              <PolarRadiusAxis tick={false} tickLine={false} axisLine={false}>
                <Label
                  content={({ viewBox }) => {
                    if (viewBox && "cx" in viewBox && "cy" in viewBox) {
                      return (
                        <text x={viewBox.cx} y={viewBox.cy} textAnchor="middle">
                          <tspan
                            x={viewBox.cx}
                            y={(viewBox.cy || 0) - 16}
                            className="fill-foreground text-2xl font-bold"
                          >
                            {totalVisitors.toLocaleString()}%
                          </tspan>
                        </text>
                      );
                    }
                  }}
                />
              </PolarRadiusAxis>
              <RadialBar
                dataKey="desktop"
                stackId="a"
                cornerRadius={5}
                fill="var(--color-desktop)"
                className="stroke-transparent stroke-2"
                background={true}
              />
            </RadialBarChart>
          </ChartContainer>
        </div>
      </CardContent>
      <CardFooter className="-mt-20">
        <div className="text-xs leading-snug text-gray-700">
        The student has exhibited an outstanding approach to mastering their subjects, leveraging Prejee resources to achieve remarkable results. 
        </div>
      </CardFooter>
    </Card>
  );
}
