"use client"; import { useEffect } from "react"; import { Plus, Pencil, Trash2, Check, X } from "lucide-react"; import { cn } from "@/lib/utils"; import { useLocale } from "@/lib/i18n/provider"; import { useConversationList } from "./use-conversation-list"; import type { Conversation } from "./conversation-menu"; import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, } from "@/components/ui/alert-dialog"; /** * Persistent conversation list for the desktop-fullscreen chat layout — * ChatGPT/Claude-style, always visible rather than a dropdown (that's * ConversationMenu, used in the drawer/mobile layout instead). Shares its * fetch/rename/delete logic with ConversationMenu via useConversationList. */ export function ConversationSidebar({ activeId, onSelect, onCreated, onDeletedActive, className, }: { activeId: string | null; onSelect: (id: string) => void; onCreated: (conversation: Conversation) => void; onDeletedActive: () => void; className?: string; }) { const { locale } = useLocale(); const { t, conversations, loading, load, create, renamingId, renameValue, setRenameValue, startRename, cancelRename, submitRename, deleteTargetId, setDeleteTargetId, confirmDelete, } = useConversationList(onDeletedActive, activeId); useEffect(() => { void load(); // eslint-disable-next-line react-hooks/exhaustive-deps -- load() is idempotent (guarded by its own `loaded` flag), only needs to run once on mount }, []); async function handleCreate() { const created = await create(); if (created) onCreated(created); } return (
{loading &&

{t("loading")}

} {!loading && conversations.length === 0 && (

{t("empty")}

)} {!loading && conversations.map((c) => (
{renamingId === c.id ? ( <> setRenameValue(e.target.value)} onKeyDown={(e) => { if (e.key === "Enter") void submitRename(); if (e.key === "Escape") cancelRename(); }} maxLength={100} className="flex-1 min-w-0 bg-transparent border-b border-primary text-sm outline-none" /> ) : ( <> )}
))}
{ if (!v) setDeleteTargetId(null); }}> {t("deleteConfirmTitle")} {t("deleteConfirmDescription")} {t("deleteCancel")} { void confirmDelete(); }} className="bg-destructive text-destructive-foreground hover:bg-destructive/90" > {t("deleteConfirm")}
); }