"use client"; import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from "@/components/ui/card"; import { cn } from "@/lib/utils"; interface FunnelStep { label: string; value: number; color?: string; } interface ChartCard21Props { title?: string; description?: string; data?: FunnelStep[]; className?: string; } const numberFormatter = new Intl.NumberFormat("fa-IR", { maximumFractionDigits: 0, }); const oneDecimalFormatter = new Intl.NumberFormat("fa-IR", { maximumFractionDigits: 1, minimumFractionDigits: 1, }); const defaultData: FunnelStep[] = [ { label: "بازدیدکنندگان", value: 10000 }, { label: "سرنخ‌ها", value: 6500 }, { label: "واجد شرایط", value: 3200 }, { label: "پیشنهادها", value: 1800 }, { label: "بسته‌شده", value: 950 }, ]; const ChartCard21 = ({ title = "قیف فروش", description = "نرخ تبدیل در مراحل قیف", data = defaultData, className, }: ChartCard21Props) => { const maxValue = Math.max(...data.map((d) => d.value)); const colors = [ "ارزش افزوده(--chart-1)", "ارزش افزوده(--chart-2)", "ارزش افزوده(--chart-3)", "ارزش افزوده(--chart-4)", "ارزش افزوده(--chart-5)", ]; return ( {title} {description}
{data.map((step, index) => { const widthPercent = (step.value / maxValue) * 100; const conversionRate = index > 0 ? (step.value / data[index - 1].value) * 100 : null; return (
{step.label}
{numberFormatter.format(step.value)} {conversionRate !== null && ( ({oneDecimalFormatter.format(conversionRate)}٪) )}
{widthPercent > 15 && ( {numberFormatter.format( Math.round((step.value / maxValue) * 100), )} ٪ )}
); })}
); }; export { ChartCard21 };