import { useState } from 'react'; import { History, MessageSquare, Plus, X } from 'lucide-react'; import type { Chat, WorkspacePane } from '@/api/types'; import { ContextMenu, ContextMenuContent, ContextMenuItem, ContextMenuSeparator, ContextMenuTrigger, } from '@/components/ui/context-menu'; import { cn } from '@/lib/utils'; interface Props { pane: WorkspacePane; tabs: Chat[]; onSwitchTab: (tabIdx: number) => void; onRemoveTab: (chatId: string) => void; onCloseOthers: (chatId: string) => void; onCloseToRight: (chatId: string) => void; onCloseAll: () => void; onNewChat: () => void; onShowHistory: () => void; onRename: (chatId: string, name: string) => Promise; onRemovePane?: () => void; } export function ChatTabBar({ pane, tabs, onSwitchTab, onRemoveTab, onCloseOthers, onCloseToRight, onCloseAll, onNewChat, onShowHistory, onRename, onRemovePane, }: Props) { const [renamingId, setRenamingId] = useState(null); const [renameValue, setRenameValue] = useState(''); function startRename(chatId: string, currentName: string | null) { setRenamingId(chatId); setRenameValue(currentName ?? ''); } async function finishRename() { if (renamingId && renameValue.trim()) { await onRename(renamingId, renameValue.trim()); } setRenamingId(null); } return (
{tabs.map((chat, tabIdx) => { const isActive = tabIdx === pane.activeChatIdx; const isLast = tabIdx === tabs.length - 1; const onlyTab = tabs.length === 1; const label = chat.name ?? 'New chat'; return (
onSwitchTab(tabIdx)} className={cn( 'group flex items-center gap-1.5 px-3 py-1.5 text-xs border-r border-border cursor-default select-none shrink-0', isActive ? 'bg-background text-foreground' : 'bg-muted/30 text-muted-foreground hover:bg-muted/60' )} > {renamingId === chat.id ? ( setRenameValue(e.target.value)} onBlur={() => void finishRename()} onKeyDown={(e) => { if (e.key === 'Enter') void finishRename(); if (e.key === 'Escape') setRenamingId(null); }} onClick={(e) => e.stopPropagation()} className="bg-transparent border-b border-border text-xs outline-none w-28" /> ) : ( {label} )}
startRename(chat.id, chat.name)}> Rename onRemoveTab(chat.id)}> Close onCloseOthers(chat.id)} > Close others onCloseToRight(chat.id)} > Close to right onCloseAll()}> Close all
); })} {tabs.length === 0 && (
Session
)}
{onRemovePane && ( )}
); }