import React from 'react'; import { MessageSquare, Plus, Trash2, X } from 'lucide-react'; import { Session } from '../types'; import { formatConversationalTime } from '../utils'; interface Props { isOpen: boolean; onClose: () => void; sessions: Session[]; currentSessionId: string | null; onSelectSession: (id: string) => void; onNewChat: () => void; onDeleteSession: (id: string) => void; } export function Sidebar({ isOpen, onClose, sessions, currentSessionId, onSelectSession, onNewChat, onDeleteSession }: Props) { // Group sessions const groupedSessions = sessions.reduce((acc, session) => { // Fallback to current time if updated_at is missing, ensuring session is shown const timestamp = session.updated_at ? session.updated_at * 1000 : Date.now(); const date = new Date(timestamp); const today = new Date(); const yesterday = new Date(today); yesterday.setDate(yesterday.getDate() - 1); let key = 'Older'; if (date.toDateString() === today.toDateString()) key = 'Today'; else if (date.toDateString() === yesterday.toDateString()) key = 'Yesterday'; if (!acc[key]) acc[key] = []; acc[key].push(session); return acc; }, {} as Record); const groups = ['Today', 'Yesterday', 'Older'].filter(g => groupedSessions[g]?.length); return ( <> {/* Mobile Overlay */}
{/* Sidebar Panel */}

Your Journey

{sessions.length === 0 ? (

No recorded sessions.

Start a new journey above.

) : ( groups.map(group => (

{group}

{groupedSessions[group].map(session => (
{ onSelectSession(session.id); if (window.innerWidth < 768) onClose(); }} >

{session.title}

{formatConversationalTime(new Date((session.updated_at || Date.now() / 1000) * 1000))}

))}
)) )}
if.emotion v3.1 // journey
); }