"use client"; import { useState } from "react"; import { formatCurrency, dealRisk } from "@/lib/crm"; import type { Deal, Account, Product, Salesperson } from "@/lib/crm"; import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"; import { Package } from "lucide-react"; import { cn } from "@/lib/utils"; function initials(name?: string) { if (!name) return "?"; return name .split(" ") .map((p) => p[0]) .slice(0, 2) .join("") .toUpperCase(); } /** Small rounded product thumbnail with a graceful icon fallback. */ function ProductThumb({ product }: { product?: Product }) { const [failed, setFailed] = useState(false); if (!product || failed || !product.photoUrl) { return (
); } return ( {product.name} setFailed(true)} className="h-9 w-9 shrink-0 rounded-lg border border-border object-cover" /> ); } export function DealCard({ deal, account, contactName, product, owner, selected, onSelect, }: { deal: Deal; account?: Account; contactName?: string; /** Resolved product for the deal's first line item (for the thumbnail). */ product?: Product; /** Resolved deal owner (for the avatar). */ owner?: Salesperson; selected: boolean; onSelect: (id: string) => void; }) { const risk = dealRisk(deal); const ownerName = owner?.name ?? deal.ownerName; return ( ); }