"use client"; import { useState } from "react"; import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from "@/components/ui/card"; import { cn } from "@/lib/utils"; interface RingData { label: string; value: number; max: number; color: string; } interface ChartCard18Props { title?: string; description?: string; rings?: RingData[]; className?: string; } const numberFormatter = new Intl.NumberFormat("fa-IR", { maximumFractionDigits: 0, }); const defaultRings: RingData[] = [ { label: "حرکت", value: 420, max: 500, color: "var(--chart-5)" }, { label: "ورزش", value: 28, max: 30, color: "var(--chart-1)" }, { label: "ایستادن", value: 10, max: 12, color: "var(--chart-2)" }, ]; const ChartCard18 = ({ title = "حلقه‌های فعالیت", description = "پیشرفت فعالیت روزانه", rings = defaultRings, className, }: ChartCard18Props) => { const [activeIndex, setActiveIndex] = useState(null); const size = 180; const strokeWidth = 16; const gap = 6; return ( {title} {description}
{rings.map((ring, index) => { const radius = (size - strokeWidth) / 2 - index * (strokeWidth + gap); const circumference = 2 * Math.PI * radius; const percentage = Math.min(ring.value / ring.max, 1); const strokeDashoffset = circumference * (1 - percentage); const isActive = activeIndex === index; const isInactive = activeIndex !== null && activeIndex !== index; return ( setActiveIndex(index)} onMouseLeave={() => setActiveIndex(null)} > ); })}
{rings.map((ring, index) => { const percentage = Math.round((ring.value / ring.max) * 100); const isActive = activeIndex === index; const isInactive = activeIndex !== null && activeIndex !== index; return (
setActiveIndex(index)} onMouseLeave={() => setActiveIndex(null)} >
{ring.label}
{numberFormatter.format(ring.value)}/ {numberFormatter.format(ring.max)} ( {numberFormatter.format(percentage)}٪)
); })}
); }; export { ChartCard18 };