import React, { useState } from 'react'; import { Plus, Search, Pin, MessageSquare, Trash2, Edit3, Settings, Activity, PanelLeftClose, PanelLeftOpen, Check, X, Folder } from 'lucide-react'; import type { Conversation } from '../types/chat'; interface SidebarProps { conversations: Conversation[]; activeId: string; onSelectConversation: (id: string) => void; onNewChat: () => void; onDeleteChat: (id: string) => void; onRenameChat: (id: string, title: string) => void; onPinChat: (id: string) => void; onOpenSettings: () => void; onOpenDashboard: () => void; open: boolean; setOpen: (val: boolean) => void; } export const Sidebar: React.FC = ({ conversations, activeId, onSelectConversation, onNewChat, onDeleteChat, onRenameChat, onPinChat, onOpenSettings, onOpenDashboard, open, setOpen }) => { const [searchTerm, setSearchTerm] = useState(''); const [editingId, setEditingId] = useState(null); const [editingTitle, setEditingTitle] = useState(''); const filtered = conversations.filter(c => c.title.toLowerCase().includes(searchTerm.toLowerCase()) ); const pinned = filtered.filter(c => c.pinned); const recent = filtered.filter(c => !c.pinned); const handleStartRename = (c: Conversation) => { setEditingId(c.id); setEditingTitle(c.title); }; const handleSaveRename = (id: string) => { if (editingTitle.trim()) { onRenameChat(id, editingTitle.trim()); } setEditingId(null); }; return ( ); }; interface ItemProps { conversation: Conversation; active: boolean; open: boolean; editing: boolean; editingTitle: string; setEditingTitle: (val: string) => void; onSelect: () => void; onStartRename: () => void; onSaveRename: () => void; onCancelRename: () => void; onDelete: () => void; onPin: () => void; } const ConversationItem: React.FC = ({ conversation, active, open, editing, editingTitle, setEditingTitle, onSelect, onStartRename, onSaveRename, onCancelRename, onDelete, onPin }) => { return (
{editing ? ( setEditingTitle(e.target.value)} onKeyDown={e => e.key === 'Enter' && onSaveRename()} className="w-full px-2 py-1 text-xs bg-slate-900 border border-blue-500 rounded-lg text-white outline-none" autoFocus /> ) : ( {conversation.title} )}
{open && (
{editing ? ( <> ) : ( <> )}
)}
); };