import type { FC } from 'react' import { memo } from 'react' import { getUserColor } from '@/app/components/workflow/collaboration/utils/user-color' import { useAppContext } from '@/context/app-context' import Avatar from '@/app/components/base/avatar' type User = { id: string name: string avatar_url?: string | null } type UserAvatarListProps = { users: User[] maxVisible?: number size?: number className?: string showCount?: boolean } export const UserAvatarList: FC = memo(({ users, maxVisible = 3, size = 24, className = '', showCount = true, }) => { const { userProfile } = useAppContext() if (!users.length) return null const shouldShowCount = showCount && users.length > maxVisible const actualMaxVisible = shouldShowCount ? Math.max(1, maxVisible - 1) : maxVisible const visibleUsers = users.slice(0, actualMaxVisible) const remainingCount = users.length - actualMaxVisible const currentUserId = userProfile?.id return (
{visibleUsers.map((user, index) => { const isCurrentUser = user.id === currentUserId const userColor = isCurrentUser ? undefined : getUserColor(user.id) return (
) }, )} {shouldShowCount && remainingCount > 0 && (
+{remainingCount}
)}
) }) UserAvatarList.displayName = 'UserAvatarList'