import React, { useState, useEffect, useRef } from 'react'; import { ChatMessage, User } from '../types'; import { Send, MessageSquare, Users, ShieldAlert, X, Minimize2, Maximize2 } from 'lucide-react'; interface ChatSystemProps { currentUser: User; onSendMessage: (text: string, channel: 'global' | 'team' | 'match') => void; messages: ChatMessage[]; } const CHAT_BOT_NAMES = ['ViperStrike', 'NeonNinja', 'SniperPro77', 'ShadowDemon', 'T1_Fanboy', 'ToxicReaper', 'MLBB_Queen']; const CHAT_BOT_ALIVE_TEXTS = [ 'Anyone watching the Grand Finals live currently?', 'That triple kill in game 2 was actually insane...', 'Who wants to join my solo lobby for some practice scrims?', 'Sentinels are playing crazy good tactics today.', 'Can we talk about the latest update balance patches?', 'MLBB draft selection was so meta.', 'Registering my team right now. Let us go cybergang!', 'Dota 2 bracket looks stacked this phase.', 'Let us showcase our badges on the pro league ranks!' ]; export const ChatSystem: React.FC = ({ currentUser, onSendMessage, messages }) => { const [isOpen, setIsOpen] = useState(false); const [channel, setChannel] = useState<'global' | 'team' | 'match'>('global'); const [inputText, setInputText] = useState(''); const [unreadCount, setUnreadCount] = useState(0); const scrollRef = useRef(null); // Auto-scroll chat to bottom useEffect(() => { if (scrollRef.current && isOpen) { scrollRef.current.scrollTop = scrollRef.current.scrollHeight; } }, [messages, isOpen]); // Keep track of unread messages when closed useEffect(() => { if (!isOpen) { setUnreadCount((prev) => prev + 1); } }, [messages]); // Reset unread counts when opened useEffect(() => { if (isOpen) { setUnreadCount(0); } }, [isOpen]); const handleSend = (e: React.FormEvent) => { e.preventDefault(); if (!inputText.trim()) return; onSendMessage(inputText, channel); setInputText(''); }; const filteredMessages = messages.filter((m) => m.channel === channel); return (
{/* Floating Chat Button */} {!isOpen && ( )} {/* Chat Window */} {isOpen && (
{/* Header */}

Nova Esports Chat Stream

{/* Channel Tabs */}
{/* Message List */}
{filteredMessages.length === 0 ? (

No chatter in this chamber yet.

Be the first to spark the fire!

) : ( filteredMessages.map((msg) => { const isAdmin = msg.role === 'admin'; const isMe = msg.userId === currentUser.id; return (
{/* Avatar */}
{msg.userAvatar && (msg.userAvatar.startsWith('http://') || msg.userAvatar.startsWith('https://')) ? ( ) : ( msg.userAvatar || '👤' )}
{/* Content Block */}
{msg.username} {isAdmin && ( Admin )} {msg.timestamp}
{msg.message}
); }) )}
{/* Message Input */}
setInputText(e.target.value)} placeholder={`Send message to #${channel}...`} maxLength={150} className="flex-1 bg-[#020205]/60 border border-white/10 hover:border-cyan-500/30 focus:border-cyan-500 text-white rounded-lg px-3 py-1.5 text-xs outline-none focus:ring-1 focus:ring-cyan-500/20 transition-all font-sans" />
)}
); };