import * as React from 'react'; import * as AvatarPrimitive from '@radix-ui/react-avatar'; import { cn } from '@/lib/utils'; // Primitives const Avatar = React.forwardRef< React.ElementRef, React.ComponentPropsWithoutRef >(({ className, ...props }, ref) => ( )); Avatar.displayName = AvatarPrimitive.Root.displayName; const AvatarImage = React.forwardRef< React.ElementRef, React.ComponentPropsWithoutRef >(({ className, ...props }, ref) => ( )); AvatarImage.displayName = AvatarPrimitive.Image.displayName; const AvatarFallback = React.forwardRef< React.ElementRef, React.ComponentPropsWithoutRef >(({ className, ...props }, ref) => ( )); AvatarFallback.displayName = AvatarPrimitive.Fallback.displayName; // Smart Component (renamed to UserAvatar) export interface UserAvatarProps { src?: string | null; alt?: string; name?: string; size?: 'sm' | 'md' | 'lg' | 'xl'; className?: string; } const sizeClasses = { sm: 'w-8 h-8 text-xs', md: 'w-12 h-12 text-sm', lg: 'w-16 h-16 text-base', xl: 'w-32 h-32 text-xl', }; export function UserAvatar({ src, alt, name, size = 'md', className = '', }: UserAvatarProps) { const [imageError, setImageError] = React.useState(false); const sizeClass = sizeClasses[size]; const getInitials = (name?: string): string => { if (!name) return '?'; const parts = name.trim().split(' '); if (parts.length >= 2) { return (parts[0][0] + parts[parts.length - 1][0]).toUpperCase(); } return name.substring(0, 2).toUpperCase(); }; const initials = getInitials(name || alt); return ( {src && !imageError ? ( { if (status === 'error') setImageError(true); }} /> ) : null} {initials} ); } export { Avatar, AvatarImage, AvatarFallback };