"use client"; import Image from "../embed-shims/next-image"; import { getProxiedImageUrl } from "../utils/image-proxy-stub"; interface Props { name: string; email: string; avatarUrl?: string | null; /** Optional subtitle text (e.g., relative time) to replace email line */ subtitle?: string | null; /** Authentication provider names (e.g. ["google", "microsoft"]) */ authProviders?: string[]; /** Show an outline Edit Profile button that routes to editHref */ showEditButton?: boolean; /** Path to navigate when Edit button clicked (default "/profile/edit") */ editHref?: string; /** Optional userId/profile passed through to EditProfileButton (for analytics) */ userId?: string; profileData?: any; /** Optional MSP preview info to render below email */ mspPreview?: { name?: string | null; seatCount?: number | null; technicianCount?: number | null; annualRevenue?: number | null; logoUrl?: string | null; } | null; /** Compact mode (avatar + name row, used in comment headers) */ compact?: boolean; /** Avatar size in px for compact mode (defaults 40) */ avatarSize?: number; /** When true, replaces the static avatar with the ProfilePhotoUpload widget */ editablePhoto?: boolean; /** Required when editablePhoto=true – receives new photo URL */ onPhotoChange?: (url: string | null) => void; } const getAuthProviderIcon = (provider: string) => { const p = provider.toLowerCase(); switch (p) { case "google": return Google; case "microsoft": case "azure": return Microsoft; case "slack": case "slack_oidc": return
; default: return
; } }; // Abbreviate large numbers: 1 200 → 1.2K , 15 000 → 15K , 2 000 000 → 2M const formatNumber = (n: number) => { if (n >= 1_000_000_000) { const value = n / 1_000_000_000; return `${Number.isInteger(value) ? value.toFixed(0) : value.toFixed(1)}B`; } if (n >= 1_000_000) { const value = n / 1_000_000; return `${Number.isInteger(value) ? value.toFixed(0) : value.toFixed(1)}M`; } if (n >= 1_000) { return `${Math.round(n / 1_000)}K`; } return n.toLocaleString(); }; export function UserSummary({ name, email, subtitle = null, avatarUrl, authProviders, showEditButton = false, editHref = "/profile/edit", userId, profileData, mspPreview, compact = false, avatarSize = 40, editablePhoto = false, onPhotoChange, }: Props) { // Compact variant: minimal horizontal row if (compact) { return (
{avatarUrl ? ( {name} ) : (
{name.split(' ').map((n: string) => n.charAt(0)).join('').slice(0, 2)}
)} {mspPreview && mspPreview.logoUrl && ( {mspPreview.name )}

{name} {mspPreview?.name && ( • {mspPreview.name} )}

0 ? subtitle : (email && email.trim().length > 0 ? email : '\u00A0')}> {subtitle && subtitle.trim().length > 0 ? subtitle : (email && email.trim().length > 0 ? email : '\u00A0')}

); } return (
{/* Header Row */}
{/* Avatar with badge wrapper */}
{avatarUrl ? ( {name} ) : (
{name.charAt(0).toUpperCase()}
)} {/* MSP logo badge (show only when MSP exists) */} {mspPreview && (
{mspPreview.logoUrl ? ( {mspPreview.name ) : ( {mspPreview.name?.charAt(0).toUpperCase() || '?'} )}
)}
{/* Info + actions block */}
{/* LEFT : text stack */}

{name}

0) ? subtitle : (email && email.trim().length > 0 ? email : '\u00A0')}> {(subtitle && subtitle.trim().length > 0) ? subtitle : (email && email.trim().length > 0 ? email : '\u00A0')}

{mspPreview && (() => { const mspSegments = [ mspPreview.name ?? '—', typeof mspPreview.seatCount === 'number' ? `${formatNumber(mspPreview.seatCount)} Seats` : null, typeof mspPreview.technicianCount === 'number' ? `${formatNumber(mspPreview.technicianCount)} Technicians` : null, typeof mspPreview.annualRevenue === 'number' ? `$${formatNumber(mspPreview.annualRevenue)}` : null, ].filter(Boolean) as string[]; const mspTitle = mspSegments.join(' • '); return (

{/* Build string with separators */} {mspSegments .flatMap((txt, idx) => (idx === 0 ? [txt] : [' • ', txt])) .map((seg, idx) => ( {seg} ))}

); })()}
{/* RIGHT (desktop) */} {(authProviders?.length || showEditButton) && (
{/* top part */} {authProviders && authProviders.length > 0 && (
Authorized by
{authProviders.map((p) => (
{getAuthProviderIcon(p)}
))}
)} {/* bottom part - Edit button would go here */} {showEditButton && (
Edit Profile
)}
)}
{/* Mobile row: Authorized by left, Edit btn right */} {(authProviders?.length || showEditButton) && (
{authProviders && authProviders.length > 0 && (
Authorized by
{authProviders.map((p) => (
{getAuthProviderIcon(p)}
))}
)} {showEditButton && (
Edit Profile
)}
)}
); }