import React, { useState } from 'react'; function ChatList({ chats, currentChat, onSelectChat, onDeleteChat, onCreateNewChat, collapsed, isStreamingChat }) { const [hoveredChat, setHoveredChat] = useState(null); const formatDate = (timestamp) => { const date = new Date(timestamp); const now = new Date(); const diffTime = Math.abs(now - date); const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24)); if (diffDays === 1) return 'Today'; if (diffDays === 2) return 'Yesterday'; if (diffDays <= 7) return `${diffDays} days ago`; return date.toLocaleDateString(); }; const truncateTitle = (title, maxLength = 25) => { if (title.length <= maxLength) return title; return title.substring(0, maxLength) + '...'; }; return (
{/* New Chat Button */}
{/* Chat List */}
{chats.length === 0 ? (

No conversations yet

Start a new conversation to get started

) : (
{chats.map(chat => { const isActive = chat.id === currentChat?.id; const isStreaming = isStreamingChat && typeof isStreamingChat === 'function' && isStreamingChat(chat.id); const isHovered = hoveredChat === chat.id; return (
onSelectChat(chat.id)} onMouseEnter={() => setHoveredChat(chat.id)} onMouseLeave={() => setHoveredChat(null)} > {/* Streaming indicator */} {isStreaming && (
)}
{/* Chat icon */}
{isStreaming ? (
) : ( )}
{/* Chat title */}

{truncateTitle(chat.title)}

{/* Message count and date */}
{chat.messages?.length || 0} messages {chat.messages?.length > 0 && ( {formatDate(chat.messages[chat.messages.length - 1]?.timestamp || Date.now())} )}
{/* Delete button */}
); })}
)}
{/* Footer */}
{chats.length} conversation{chats.length !== 1 ? 's' : ''}
); } export default ChatList;