'use client' import { useState } from 'react' import { formatDistanceToNow } from 'date-fns' import { fr } from 'date-fns/locale/fr' import { enUS } from 'date-fns/locale/en-US' import { MessageSquare, Trash2, Plus, X } from 'lucide-react' import { Button } from '@/components/ui/button' import { cn } from '@/lib/utils' import { useLanguage } from '@/lib/i18n' interface ChatSidebarProps { conversations: any[] currentId?: string | null onSelect: (id: string) => void onNew: () => void onDelete?: (id: string) => void } export function ChatSidebar({ conversations, currentId, onSelect, onNew, onDelete, }: ChatSidebarProps) { const { t, language } = useLanguage() const dateLocale = language === 'fr' ? fr : enUS const [pendingDelete, setPendingDelete] = useState(null) const confirmDelete = (id: string) => { setPendingDelete(id) } const cancelDelete = (e: React.MouseEvent) => { e.stopPropagation() setPendingDelete(null) } const executeDelete = async (e: React.MouseEvent, id: string) => { e.stopPropagation() setPendingDelete(null) if (onDelete) { await onDelete(id) } } return (
{conversations.length === 0 ? (
{t('chat.noHistory')}
) : ( conversations.map((chat) => (
onSelect(chat.id)} className={cn( "relative cursor-pointer rounded-lg transition-all group", currentId === chat.id ? "bg-primary/10 text-primary dark:bg-primary/20" : "hover:bg-muted/50 text-muted-foreground" )} >
{chat.title || t('chat.untitled')}
{formatDistanceToNow(new Date(chat.updatedAt), { addSuffix: true, locale: dateLocale })}
{/* Delete button — visible on hover or when confirming */} {pendingDelete !== chat.id && ( )} {/* Inline confirmation banner */} {pendingDelete === chat.id && (
e.stopPropagation()} > {t('chat.deleteConfirm')}
)}
)) )}
) }