"use client" import { ChevronDown, ChevronUp, MessageSquare, Search, Trash2, X, } from "lucide-react" import Image from "next/image" import { useState } from "react" import ExamplePanel from "@/components/chat-example-panel" import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, } from "@/components/ui/alert-dialog" interface SessionMetadata { id: string title: string updatedAt: number thumbnailDataUrl?: string } interface ChatLobbyProps { sessions: SessionMetadata[] onSelectSession: (id: string) => void onDeleteSession?: (id: string) => void setInput: (input: string) => void setFiles: (files: File[]) => void dict: { sessionHistory?: { recentChats?: string searchPlaceholder?: string noResults?: string justNow?: string deleteTitle?: string deleteDescription?: string } examples?: { quickExamples?: string } common: { delete: string cancel: string } } } // Helper to format session date function formatSessionDate( timestamp: number, dict?: { justNow?: string }, ): string { const date = new Date(timestamp) const now = new Date() const diffMs = now.getTime() - date.getTime() const diffMins = Math.floor(diffMs / (1000 * 60)) const diffHours = Math.floor(diffMs / (1000 * 60 * 60)) if (diffMins < 1) return dict?.justNow || "Just now" if (diffMins < 60) return `${diffMins}m ago` if (diffHours < 24) return `${diffHours}h ago` return date.toLocaleDateString(undefined, { month: "short", day: "numeric", }) } export function ChatLobby({ sessions, onSelectSession, onDeleteSession, setInput, setFiles, dict, }: ChatLobbyProps) { // Track whether examples section is expanded (collapsed by default when there's history) const [examplesExpanded, setExamplesExpanded] = useState(false) // Delete confirmation dialog state const [deleteDialogOpen, setDeleteDialogOpen] = useState(false) const [sessionToDelete, setSessionToDelete] = useState(null) // Search filter for history const [searchQuery, setSearchQuery] = useState("") const hasHistory = sessions.length > 0 if (!hasHistory) { // Show full examples when no history return } // Show history + collapsible examples when there are sessions return (
{/* Recent Chats Section */}

{dict.sessionHistory?.recentChats || "Recent Chats"}

{/* Search Bar */}
setSearchQuery(e.target.value)} className="w-full pl-9 pr-3 py-2 text-sm rounded-lg border border-border/60 bg-background focus:outline-none focus:ring-2 focus:ring-primary/30 focus:border-primary/50 transition-all" /> {searchQuery && ( )}
{sessions .filter((session) => session.title .toLowerCase() .includes(searchQuery.toLowerCase()), ) .map((session) => ( // biome-ignore lint/a11y/useSemanticElements: Cannot use button - has nested delete button which causes hydration error
onSelectSession(session.id)} onKeyDown={(e) => { if (e.key === "Enter" || e.key === " ") { e.preventDefault() onSelectSession(session.id) } }} > {session.thumbnailDataUrl ? (
) : (
)}
{session.title}
{formatSessionDate( session.updatedAt, dict.sessionHistory, )}
{onDeleteSession && ( )}
))} {sessions.filter((s) => s.title .toLowerCase() .includes(searchQuery.toLowerCase()), ).length === 0 && searchQuery && (

{dict.sessionHistory?.noResults || "No chats found"}

)}
{/* Collapsible Examples Section */}
{examplesExpanded && (
)}
{/* Delete Confirmation Dialog */} {dict.sessionHistory?.deleteTitle || "Delete this chat?"} {dict.sessionHistory?.deleteDescription || "This will permanently delete this chat session and its diagram. This action cannot be undone."} {dict.common.cancel} { if (sessionToDelete && onDeleteSession) { onDeleteSession(sessionToDelete) } setDeleteDialogOpen(false) setSessionToDelete(null) }} className="border border-red-300 bg-red-50 text-red-700 hover:bg-red-100 hover:border-red-400" > {dict.common.delete}
) }