import { Check, ChevronDown, ChevronRight, Edit3, Folder, FolderOpen, Plus, Star, Trash2, X, } from 'lucide-react'; import { SidebarSessionItem } from '@/components/refactored/sidebar/view/SidebarSessionItem'; import type { WorkspaceRecord } from '@/components/refactored/sidebar/types'; import { getWorkspaceDisplayName } from '@/components/refactored/sidebar/utils/workspaceTransforms'; import { cn } from '@/lib/utils'; import { Button } from '@/shared/view/ui'; type SidebarWorkspaceItemProps = { workspace: WorkspaceRecord; isExpanded: boolean; selectedSessionId: string | null; editingWorkspacePath: string | null; editingWorkspaceName: string; isSavingWorkspaceName: boolean; editingSessionId: string | null; editingSessionName: string; isSavingSessionName: boolean; onEditingWorkspaceNameChange: (name: string) => void; onEditingSessionNameChange: (name: string) => void; onToggleWorkspace: (workspaceId: string, workspacePath: string) => void; onToggleWorkspaceStar: (workspaceId: string) => void; onStartWorkspaceRename: (workspace: WorkspaceRecord) => void; onCancelWorkspaceRename: () => void; onSaveWorkspaceRename: () => void; onStartSessionRename: (session: WorkspaceRecord['sessions'][number]) => void; onCancelSessionRename: () => void; onSaveSessionRename: () => void; onDeleteWorkspace: (workspace: WorkspaceRecord) => void; onSessionSelect: (workspacePath: string, sessionId: string) => void; onSessionDelete: (workspacePath: string, sessionId: string) => void; onNewSession: (workspaceId: string) => void; }; export function SidebarWorkspaceItem({ workspace, isExpanded, selectedSessionId, editingWorkspacePath, editingWorkspaceName, isSavingWorkspaceName, editingSessionId, editingSessionName, isSavingSessionName, onEditingWorkspaceNameChange, onEditingSessionNameChange, onToggleWorkspace, onToggleWorkspaceStar, onStartWorkspaceRename, onCancelWorkspaceRename, onSaveWorkspaceRename, onStartSessionRename, onCancelSessionRename, onSaveSessionRename, onDeleteWorkspace, onSessionSelect, onSessionDelete, onNewSession, }: SidebarWorkspaceItemProps) { const isEditing = editingWorkspacePath === workspace.workspaceOriginalPath; const hasSelectedSession = workspace.sessions.some( (session) => session.sessionId === selectedSessionId, ); const workspaceName = getWorkspaceDisplayName(workspace); const sessionCountLabel = `${workspace.sessions.length} session${ workspace.sessions.length === 1 ? '' : 's' }`; const handleSaveRename = () => { if (!isSavingWorkspaceName) { onSaveWorkspaceRename(); } }; return (
onToggleWorkspace(workspace.workspaceId, workspace.workspaceOriginalPath)} >
{isExpanded ? ( ) : ( )}
{isEditing ? ( onEditingWorkspaceNameChange(event.target.value)} className="w-full rounded-lg border-2 border-primary/40 bg-background px-3 py-2 text-sm text-foreground shadow-sm transition-all duration-200 focus:border-primary focus:shadow-md focus:outline-none" placeholder="Workspace name" autoFocus autoComplete="off" onClick={(event) => event.stopPropagation()} onKeyDown={(event) => { if (event.key === 'Enter') { handleSaveRename(); } if (event.key === 'Escape') { onCancelWorkspaceRename(); } }} style={{ fontSize: '16px', WebkitAppearance: 'none', borderRadius: '8px', }} /> ) : ( <>

{workspaceName}

{sessionCountLabel}

)}
{isEditing ? ( <> ) : ( <>
{isExpanded ? ( ) : ( )}
)}
{isExpanded && (
{workspace.sessions.length === 0 ? (

No sessions yet

) : ( workspace.sessions.map((session) => ( onStartSessionRename(session)} onCancelEdit={onCancelSessionRename} onSaveEdit={onSaveSessionRename} onSelect={() => onSessionSelect(workspace.workspaceOriginalPath, session.sessionId) } onDelete={() => onSessionDelete(workspace.workspaceOriginalPath, session.sessionId) } /> )) )}
)}
); }