"use client"; import { useState } from "react"; import { Cell, Pie, PieChart, ResponsiveContainer, Sector } from "recharts"; import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from "@/components/ui/card"; import { cn } from "@/lib/utils"; interface DataItem { name: string; value: number; color: string; } interface ChartCard5Props { title?: string; description?: string; centerValue?: string; centerLabel?: string; data?: DataItem[]; className?: string; } const numberFormatter = new Intl.NumberFormat("fa-IR", { maximumFractionDigits: 0, }); const defaultData: DataItem[] = [ { name: "دسکتاپ", value: 4520, color: "var(--chart-1)" }, { name: "موبایل", value: 3210, color: "var(--chart-2)" }, { name: "تبلت", value: 1240, color: "var(--chart-3)" }, ]; const defaultTotalVisitors = defaultData.reduce( (sum, item) => sum + item.value, 0, ); interface ActiveShapeProps { cx: number; cy: number; innerRadius: number; outerRadius: number; startAngle: number; endAngle: number; fill: string; } const renderActiveShape = (props: ActiveShapeProps) => { const { cx, cy, innerRadius, outerRadius, startAngle, endAngle, fill } = props; return ( ); }; const ChartCard5 = ({ title = "ترافیک به تفکیک دستگاه", description = "تفکیک بازدیدکنندگان بر اساس نوع دستگاه", centerValue = numberFormatter.format(defaultTotalVisitors), centerLabel = "مجموع بازدیدکنندگان", data = defaultData, className, }: ChartCard5Props) => { const [activeIndex, setActiveIndex] = useState(null); return ( {title} {description}
setActiveIndex(index)} onMouseLeave={() => setActiveIndex(null)} > {data.map((entry, index) => ( ))}
{centerValue} {centerLabel}
{data.map((item, index) => (
setActiveIndex(index)} onMouseLeave={() => setActiveIndex(null)} >
{item.name}
{numberFormatter.format(item.value)}
))}
); }; export { ChartCard5 };