import React, { useState } from 'react'; import { Card, CardContent } from '@/components/ui/card'; import { Badge } from '@/components/ui/badge'; import { Users, Circle } from 'lucide-react'; interface ActiveUser { id: string; name: string; color: string; lastSeen: Date; isTyping?: boolean; currentLine?: number; } interface ActiveUsersPanelProps { isVisible: boolean; className?: string; } export const ActiveUsersPanel: React.FC = ({ isVisible, className = '' }) => { const [activeUsers] = useState([ // Mock data for demonstration { id: '1', name: 'You', color: '#b8bb26', lastSeen: new Date(), isTyping: false, currentLine: 15, }, { id: '2', name: 'Alice', color: '#fb4934', lastSeen: new Date(Date.now() - 30000), // 30 seconds ago isTyping: true, currentLine: 8, }, { id: '3', name: 'Bob', color: '#83a598', lastSeen: new Date(Date.now() - 120000), // 2 minutes ago isTyping: false, currentLine: 23, }, ]); const getStatusIndicator = (user: ActiveUser) => { const timeDiff = Date.now() - user.lastSeen.getTime(); if (timeDiff < 60000) { // Less than 1 minute return { status: 'online', color: 'rgb(184, 187, 38)' }; // success color } else if (timeDiff < 300000) { // Less than 5 minutes return { status: 'away', color: 'rgb(250, 189, 47)' }; // warning color } else { return { status: 'offline', color: 'rgb(146, 131, 116)' }; // muted color } }; const formatLastSeen = (date: Date) => { const timeDiff = Date.now() - date.getTime(); if (timeDiff < 60000) { return 'Just now'; } else if (timeDiff < 3600000) { const minutes = Math.floor(timeDiff / 60000); return `${minutes}m ago`; } else { const hours = Math.floor(timeDiff / 3600000); return `${hours}h ago`; } }; if (!isVisible) { return null; } return (
{/* Users List */}
{activeUsers.length === 0 ? (

No users

) : ( activeUsers.map((user) => { const { status, color } = getStatusIndicator(user); return (
{user.name.charAt(0).toUpperCase()}

{user.name}

{formatLastSeen(user.lastSeen)}

{status}
{user.currentLine && (
L{user.currentLine} {user.isTyping && (
)}
)} ); }) )}
{/* Footer with total count */}
{activeUsers.filter(u => getStatusIndicator(u).status === 'online').length} online {activeUsers.filter(u => u.isTyping).length} typing
); };