import { SessionSummary } from "@/hooks/use-chat-storage"; import { Button } from "@/components/ui/button"; import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip"; import { Trash2, Plus, MessageSquare } from "lucide-react"; import { cn } from "@/lib/utils"; interface SidebarListProps { sessions: SessionSummary[]; currentSessionId: string | null; onSelectSession: (id: string) => void; onDeleteSession: (id: string) => void; onNewChat: () => void; } function formatDate(dateString: string) { const date = new Date(dateString); const now = new Date(); const diffInMs = now.getTime() - date.getTime(); const diffInHours = diffInMs / (1000 * 60 * 60); const diffInDays = diffInMs / (1000 * 60 * 60 * 24); // Se foi hoje, mostrar apenas hora if (diffInHours < 24) { return new Intl.DateTimeFormat('pt-BR', { hour: '2-digit', minute: '2-digit' }).format(date); } // Se foi ontem if (diffInDays < 2) { return 'Ontem'; } // Se foi nos últimos 7 dias if (diffInDays < 7) { return new Intl.DateTimeFormat('pt-BR', { weekday: 'short' }).format(date); } // Caso contrário, mostrar data completa return new Intl.DateTimeFormat('pt-BR', { day: '2-digit', month: '2-digit', year: diffInDays > 365 ? 'numeric' : undefined }).format(date); } export function SidebarList({ sessions, currentSessionId, onSelectSession, onDeleteSession, onNewChat }: SidebarListProps) { return (
{/* Header com botão Nova Conversa */}
{/* Lista de chats com scroll customizado */}
{sessions.length === 0 && (

Nenhuma conversa salva

Comece uma nova conversa para começar

)} {sessions.map((session) => { const isSelected = currentSessionId === session.id; const showTooltip = session.title.length > 30; return (
onSelectSession(session.id)} role="button" tabIndex={0} onKeyDown={(e) => { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault(); onSelectSession(session.id); } }} > {/* Conteúdo do card */}
{/* Ícone/Emoji */}
{session.emoji || '💬'}
{/* Texto do card */}

{session.title}

{formatDate(session.updated_at)}

{/* Botão de deletar - aparece no hover */}
{/* Indicador de seleção */} {isSelected && (
)}
{showTooltip && (

{session.title}

{formatDate(session.updated_at)}

)} ); })}
); }