import React, { useState, useRef, useEffect } from 'react'; import MessageActions from './MessageActions'; import TypingIndicator from './TypingIndicator'; import EmojiPicker from './EmojiPicker'; const initialMessages = [ { type: 'system', division: 'foundation', label: '[FOUNDATION] System Announcement', text: 'Foundation authentication services upgraded to v2.1.0. Enhanced security protocols now active across all AeThex infrastructure.', }, { type: 'message', id: 1, author: 'Trevor', badge: 'foundation', badgeLabel: 'Foundation', time: '10:34 AM', avatar: { initial: 'T', gradient: 'linear-gradient(135deg, #ff0000, #cc0000)' }, text: 'Just pushed the authentication updates. All services should automatically migrate to the new protocols within 24 hours.', reactions: [{ emoji: '🔥', count: 3, reacted: true }, { emoji: '👍', count: 2, reacted: false }], }, { type: 'message', id: 2, author: 'Marcus', time: '10:41 AM', avatar: { initial: 'M', gradient: 'linear-gradient(135deg, #0066ff, #003380)' }, text: "Excellent work! I've been testing the new Passport integration and it's incredibly smooth. The Trinity color-coding in the UI makes it really clear which division is handling what.", }, { type: 'system', division: 'labs', label: '[LABS] Experimental Feature Alert', text: 'Nexus Engine v2.0-beta now available for testing. New cross-platform sync reduces latency by 40%. Join #labs-testing to participate.', }, { type: 'message', id: 3, author: 'Sarah', badge: 'labs', badgeLabel: 'Labs', time: '11:15 AM', avatar: { initial: 'S', gradient: 'linear-gradient(135deg, #ffa500, #ff8c00)' }, text: 'The Nexus v2 parallel compilation is insane. Cut my build time from 3 minutes to under 2. Still some edge cases with complex state synchronization but wow...', reactions: [{ emoji: '🚀', count: 5, reacted: true }], }, { type: 'message', id: 4, author: 'Anderson', badge: 'foundation', badgeLabel: 'Founder', time: '11:47 AM', avatar: { initial: 'A', gradient: 'linear-gradient(135deg, #ff0000, #0066ff, #ffa500)' }, text: 'Love seeing the Trinity infrastructure working in harmony. Foundation keeping everything secure, Labs pushing the boundaries, Corporation delivering production-ready tools. This is exactly the vision.', reactions: [{ emoji: '❤️', count: 8, reacted: false }, { emoji: '🔥', count: 4, reacted: true }], }, { type: 'message', id: 5, author: 'DevUser_2847', time: '12:03 PM', avatar: { initial: 'D' }, text: 'Quick question - when using AeThex Studio, does the Terminal automatically connect to all three Trinity divisions, or do I need to configure that?', }, { type: 'system', division: 'corporation', label: '[CORPORATION] Service Update', text: 'AeThex Studio Pro users: New Railway deployment templates available. Optimized configurations for Foundation APIs, Corporation services, and Labs experiments.', }, ]; export default function ChatArea({ onOpenSearch, onOpenThread, onPinnedClick, onNotificationsClick, onContextMenu }) { const [messages, setMessages] = useState(initialMessages); const [inputValue, setInputValue] = useState(''); const [showEmojiPicker, setShowEmojiPicker] = useState(false); const [hoveredMessage, setHoveredMessage] = useState(null); const [typingUsers] = useState(['Sarah', 'Marcus']); // Simulated typing const messagesEndRef = useRef(null); const scrollToBottom = () => { messagesEndRef.current?.scrollIntoView({ behavior: 'smooth' }); }; useEffect(() => { scrollToBottom(); }, [messages]); const handleSend = () => { if (!inputValue.trim()) return; const newMessage = { type: 'message', id: Date.now(), author: 'You', time: new Date().toLocaleTimeString([], { hour: 'numeric', minute: '2-digit' }), avatar: { initial: 'Y', gradient: 'linear-gradient(135deg, #0066ff, #003380)' }, text: inputValue, }; setMessages([...messages, newMessage]); setInputValue(''); }; const handleKeyPress = (e) => { if (e.key === 'Enter') { handleSend(); } }; const handleEmojiSelect = (emoji) => { setInputValue((prev) => prev + emoji); setShowEmojiPicker(false); }; const handleReaction = (messageId, emoji) => { setMessages((prev) => prev.map((msg) => { if (msg.id !== messageId) return msg; const reactions = msg.reactions || []; const existing = reactions.find((r) => r.emoji === emoji); if (existing) { return { ...msg, reactions: reactions.map((r) => r.emoji === emoji ? { ...r, count: r.reacted ? r.count - 1 : r.count + 1, reacted: !r.reacted } : r ).filter((r) => r.count > 0), }; } return { ...msg, reactions: [...reactions, { emoji, count: 1, reacted: true }], }; }) ); }; return (