"use client"; import { motion, AnimatePresence } from "framer-motion"; import * as Tooltip from "@radix-ui/react-tooltip"; import { Wifi, WifiOff } from "lucide-react"; import { getInitials } from "@/lib/collaboration/presence"; import { labelForRole } from "@/lib/collaboration/permissions"; import { useCollaborationContextOptional } from "./CollaborationProvider"; import { cn } from "@/lib/utils"; // ─── Single Avatar ──────────────────────────────────────────────────────────── interface AvatarProps { name: string; color: string; avatar?: string; role: import("@/lib/collaboration/socket").CollabRole; isActive?: boolean; } function UserAvatar({ name, color, avatar, role, isActive = true }: AvatarProps) { return (
{avatar ? ( // eslint-disable-next-line @next/next/no-img-element {name} ) : (
{getInitials(name)}
)} {/* Online indicator dot */} {isActive && ( )}

{name}

{labelForRole(role)}

); } // ─── PresenceAvatars ────────────────────────────────────────────────────────── export function PresenceAvatars() { const ctx = useCollaborationContextOptional(); if (!ctx) return null; const { isConnected, otherUsers, currentUser } = ctx; // Show at most 4 avatars + overflow badge const MAX_VISIBLE = 4; const allUsers = [currentUser, ...otherUsers]; const visible = allUsers.slice(0, MAX_VISIBLE); const overflow = allUsers.length - MAX_VISIBLE; return (
{/* Connection indicator */}
{isConnected ? ( ) : ( )} {isConnected ? `${allUsers.length} online` : "Reconnecting…"}
{/* Stacked avatars */}
{visible.map((user, i) => ( ))} {overflow > 0 && (
+{overflow}
)}
); }