import React from "react"; import { formatNumber } from "~/lib/utils"; interface FunnelData { name: string; value: number; label: string; percentage?: string; } interface FunnelChartProps { data: FunnelData[]; title?: string; className?: string; } const greenColors = ["#3C9F71","#3BC47A","#3BC47A","#3BD77E","#3AEA83"] export function FunnelChart({ data, title, className = "" }: FunnelChartProps) { const maxValue = Math.max(...data.map(d => d.value)); const toPercent = (value: number) => { if (!maxValue || maxValue <= 0) return 0; return Math.round((value / maxValue) * 100); }; return (
{title && (

{title}

)}
{/* Start Process Line */}
ابتدا فرآیند
۱۰۰%
{/* Funnel Bars */}
{data.map((item, index) => { const widthPercentage = toPercent(item.value); const barWidth = Math.max(20, widthPercentage); // Minimum 20% width return (
{item.label}
{item.value.toLocaleString('fa-IR')}
); })}
{/* End Process Line */}
انتها فرآیند
{(() => { const lastValue = data[data.length - 1]?.value ?? 0; const percent = toPercent(lastValue); return (
{formatNumber(percent)}%
); })()}
); }