import React from 'react'; import { motion, AnimatePresence } from 'framer-motion'; import { PlusIcon, TrashIcon, XMarkIcon, ChatBubbleLeftIcon, HomeIcon, Bars3Icon } from '@heroicons/react/24/outline'; const Sidebar = ({ open, onClose, conversations, activeConversationId, onConversationSelect, onNewChat, onDeleteConversation, onBackToHome, darkMode }) => { const formatDate = (date) => { const now = new Date(); const messageDate = new Date(date); const diffTime = Math.abs(now - messageDate); const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24)); if (diffDays === 1) return 'Today'; if (diffDays === 2) return 'Yesterday'; if (diffDays <= 7) return `${diffDays - 1} days ago`; return messageDate.toLocaleDateString(); }; const truncateTitle = (title, maxLength = 25) => { if (title.length <= maxLength) return title; return title.substring(0, maxLength) + '...'; }; return ( {open && ( <> {/* Mobile: Full-screen overlay background */} {/* Sidebar Content */} {/* Header - Mobile optimized */}
{/* Top row: Close button and title */}

Conversations

{/* Action buttons - Mobile optimized */}
{ onNewChat(); onClose(); }} className={`flex items-center justify-center gap-2 md:gap-3 px-4 py-3 md:py-2.5 rounded-xl md:rounded-lg font-medium transition-all touch-manipulation ${ darkMode ? 'bg-primary-600 hover:bg-primary-700 active:bg-primary-800 text-white shadow-lg' : 'bg-primary-500 hover:bg-primary-600 active:bg-primary-700 text-white shadow-lg' } hover:shadow-xl active:shadow-2xl flex-1 sm:flex-none`} > New Chat { onBackToHome(); onClose(); }} className={`flex items-center justify-center gap-2 md:gap-3 px-4 py-3 md:py-2.5 rounded-xl md:rounded-lg font-medium transition-all touch-manipulation ${ darkMode ? 'bg-gray-700 hover:bg-gray-600 active:bg-gray-500 text-gray-200 shadow-lg' : 'bg-gray-200 hover:bg-gray-300 active:bg-gray-400 text-gray-700 shadow-lg' } hover:shadow-xl active:shadow-2xl flex-1 sm:flex-none`} > Home
{/* Conversations List - Mobile optimized */}
{conversations.length === 0 ? (

No conversations yet

Start a new chat to begin your CA study session

) : (
{conversations.map((conv) => ( { onConversationSelect(conv.id); onClose(); }} > {/* Conversation Content */}
{/* Title */}

{truncateTitle(conv.title || 'New Conversation')}

{/* Message count and date */}
{conv.messages?.length || 0} messages {formatDate(conv.createdAt)}
{/* Last message preview - Mobile optimized */} {conv.messages && conv.messages.length > 0 && (

{conv.messages[conv.messages.length - 1].content.substring(0, 40)}...

)}
{/* Delete Button - Larger touch target for mobile */} { e.stopPropagation(); onDeleteConversation(conv.id); }} className={`p-2 md:p-1.5 rounded-lg opacity-0 md:group-hover:opacity-100 transition-all touch-manipulation ${ darkMode ? 'hover:bg-red-600/20 active:bg-red-600/30 text-red-400' : 'hover:bg-red-50 active:bg-red-100 text-red-500' } flex-shrink-0 md:opacity-100 sm:opacity-100`} title="Delete conversation" >
{/* Active indicator */} {activeConversationId === conv.id && ( )} ))}
)}
{/* Footer - Mobile optimized */}

📚 CA Study Assistant

{conversations.length} conversation{conversations.length !== 1 ? 's' : ''}

)}
); }; export default Sidebar;