import React, { useState, lazy, Suspense } from 'react'; import { ChatMessage } from '../store/chatStore'; import { useAuthStore } from '@/features/auth/store/authStore'; import { cn } from '@/lib/utils'; import { Smile, MoreHorizontal } from 'lucide-react'; import { useChat } from '../hooks/useChat'; // PERF: Lazy load EmojiPicker (composant volumineux ~200KB) const EmojiPicker = lazy(() => import('emoji-picker-react').then(module => ({ default: module.default }))); import { Theme } from 'emoji-picker-react'; import { LoadingSpinner } from '@/components/ui/loading-spinner'; interface ChatMessageProps { message: ChatMessage; } export const ChatMessageComponent: React.FC = ({ message, }) => { const { user } = useAuthStore(); const { addReaction } = useChat(); const isMe = user?.id === message.sender_id; const [showEmojiPicker, setShowEmojiPicker] = useState(false); const handleEmojiClick = (emojiData: { emoji: string }) => { addReaction(message.id, emojiData.emoji); setShowEmojiPicker(false); }; return (
{isMe ? 'Moi' : message.sender_username || `Utilisateur ${message.sender_id.slice(0, 8)}`} {new Date(message.created_at).toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' })}
{isMe && ( )}
{/* Attachments */} {message.attachments && message.attachments.length > 0 && (
{message.attachments.map((att, i) => (
{att.file_type.startsWith('image') ? ( {att.file_name} window.open(att.file_url, '_blank')} /> ) : ( {att.file_name} )}
))}
)}

{message.content}

{!isMe && ( )} {showEmojiPicker && (
setShowEmojiPicker(false)} />
}>
)}
{/* Reactions Display */} {message.reactions && Object.keys(message.reactions).length > 0 && (
{Object.entries(message.reactions).map(([emoji, users]) => ( ))}
)}
); };