import React, { useState, useEffect, useRef } from 'react'; import { ArrowLeft, Users, MoreVertical } from 'lucide-react'; import { useScreenSize } from '../../utils/responsive'; import { useAuth } from '../../contexts/AuthContext'; import MessageList from './MessageList'; import MessageInput from './MessageInput'; import TypingIndicator from './TypingIndicator'; const ChatArea = ({ conversation, messages, onNewMessage, onConversationUpdate }) => { const { user } = useAuth(); const { isMobile } = useScreenSize(); const [showSidebar, setShowSidebar] = useState(!isMobile); const [typingUsers, setTypingUsers] = useState([]); const getConversationTitle = () => { if (conversation.type === 'direct') { const otherParticipant = conversation.participants.find(p => p.user._id !== user.id); return otherParticipant?.user.displayName || 'Unknown User'; } else { return conversation.name; } }; const getParticipantCount = () => { if (conversation.type === 'direct') { return '1 member'; } else { return `${conversation.participants.length} members`; } }; const handleNewMessage = (message) => { onNewMessage(message); onConversationUpdate(conversation._id, message); }; const handleTypingStart = (data) => { if (data.userId !== user.id) { setTypingUsers(prev => [...prev.filter(id => id !== data.userId), data.userId]); } }; const handleTypingStop = (data) => { setTypingUsers(prev => prev.filter(id => id !== data.userId)); }; return (
{/* Chat Header */}
{isMobile && ( )}
{conversation.type === 'direct' ? ( getConversationTitle().charAt(0).toUpperCase() ) : ( )}

{getConversationTitle()}

{getParticipantCount()} {typingUsers.length > 0 && ( <> )}
{/* Messages Area */}
{/* Message Input */} {/* Mobile Sidebar Overlay */} {isMobile && showSidebar && (
setShowSidebar(false)}>
)}
); }; export default ChatArea;