"use client"; import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"; import { Sparkline } from "@/components/charts"; import { cn } from "@/lib/utils"; import { formatCurrency, STAGE_STYLES } from "@/lib/crm"; import type { Deal, Salesperson } from "@/lib/crm"; export interface RepStatsResult { rep: Salesperson; bookings: number; openPipeline: number; attainment: number; winRate: number | null; dealCount: number; trend: number[]; deals: Deal[]; } function Tile({ label, value }: { label: string; value: string }) { return (
{label}
{value}
); } function initials(name: string): string { return name .split(/\s+/) .filter(Boolean) .slice(0, 2) .map((p) => p[0]?.toUpperCase() ?? "") .join(""); } export function RepStatsCard({ result, status, }: { result?: RepStatsResult; status: string; }) { if (status !== "complete") { return (
Pulling up the rep’s numbers…
); } if (!result || !result.rep) { return (
Rep stats aren’t available right now.
); } const { rep } = result; const topDeals = [...result.deals] .sort((a, b) => b.amount - a.amount) .slice(0, 4); return (
{initials(rep.name)}
{rep.name}
{rep.role} · {rep.region}
{result.trend && result.trend.length > 0 && (
Bookings trend
)} {topDeals.length > 0 && (
Top deals
)}
); }