import { cx } from '@/utils/cx'; import type { Lead } from '@/types/entities'; interface SourceBreakdownProps { leads: Lead[]; } const sourceColors: Record = { FACEBOOK_AD: 'bg-brand-solid', GOOGLE_AD: 'bg-success-solid', INSTAGRAM: 'bg-error-solid', GOOGLE_MY_BUSINESS: 'bg-warning-solid', WEBSITE: 'bg-fg-brand-primary', REFERRAL: 'bg-fg-tertiary', WHATSAPP: 'bg-success-solid', WALK_IN: 'bg-fg-quaternary', PHONE: 'bg-fg-secondary', OTHER: 'bg-fg-disabled', }; const sourceLabel = (source: string): string => source.replace(/_/g, ' ').replace(/\b\w/g, (c) => c.toUpperCase()); export const SourceBreakdown = ({ leads }: SourceBreakdownProps) => { const sourceCounts = leads.reduce>((acc, lead) => { const source = lead.leadSource ?? 'OTHER'; acc[source] = (acc[source] ?? 0) + 1; return acc; }, {}); const sorted = Object.entries(sourceCounts).sort(([, a], [, b]) => b - a); const maxCount = sorted.length > 0 ? sorted[0][1] : 1; if (sorted.length === 0) { return null; } return (

Lead Sources

{sorted.map(([source, count]) => { const widthPercent = (count / maxCount) * 100; return (
{sourceLabel(source)}
{count}
); })}
); };