import { Copy, Loader2, Trash2 } from "lucide-react" import { useState } from "react" import { Button } from "@/components/ui/button" import { ScrollArea } from "@/components/ui/scroll-area" import { cn } from "@/lib/utils" import type { ChatListItem } from "../types/chat" interface ChatListProps { sessions: ChatListItem[] currentSessionId: string | null isCreatingNew: boolean onSelectSession: (id: string) => void onDeleteSession: (id: string) => void onCopySession: (id: string) => void } export function ChatList({ sessions, currentSessionId, isCreatingNew, onSelectSession, onDeleteSession, onCopySession, }: ChatListProps) { const [hoveredId, setHoveredId] = useState(null) const [showAll, setShowAll] = useState(false) // Показываем только первые 3 чата, если не раскрыто const visibleSessions = showAll ? sessions : sessions.slice(0, 3) const hiddenCount = sessions.length - 3 return (

Previous Threads

{/* Временный элемент при создании нового чата */} {isCreatingNew && (
составь план рефакторинга 1 Today
)} {/* Список существующих чатов */} {visibleSessions.map((session) => (
onSelectSession(session.id)} onMouseEnter={() => setHoveredId(session.id)} onMouseLeave={() => setHoveredId(null)} > {session.title} {/* Показываем кнопки действий при наведении */} {hoveredId === session.id ? (
) : (
{session.messageCount} messages {session.lastMessageAt ? formatDate(session.lastMessageAt) : "No date"}
)}
))} {/* Кнопка "Show more" если есть скрытые чаты */} {!showAll && hiddenCount > 0 && ( )}
) } // Функция форматирования даты function formatDate(date: Date): string { const now = new Date() const diff = now.getTime() - date.getTime() const days = Math.floor(diff / (1000 * 60 * 60 * 24)) if (days === 0) { return "Today" } if (days === 1) { return "Yesterday" } if (days < 7) { return `${days} days ago` } return date.toLocaleDateString("ru-RU", { day: "numeric", month: "short", }) }