|
| 1 | +'use client'; |
| 2 | + |
| 3 | +import React from 'react'; |
| 4 | +import { Plus, X, Zap } from 'lucide-react'; |
| 5 | +import { Button } from '@/components/ui/button'; |
| 6 | +import { cn } from '@/lib/utils'; |
| 7 | +import { SessionTab } from './SessionTab'; |
| 8 | +import type { SessionStatus } from './TerminalSession'; |
| 9 | + |
| 10 | +type Session = { |
| 11 | + id: string; |
| 12 | + label: string; |
| 13 | +}; |
| 14 | + |
| 15 | +type TerminalHeaderProps = { |
| 16 | + sessions: Session[]; |
| 17 | + activeSessionId: string; |
| 18 | + sessionStatuses: Record<string, SessionStatus>; |
| 19 | + sessionLimit: number; |
| 20 | + onAddSession: () => void; |
| 21 | + onCloseSession: (id: string) => void; |
| 22 | + onSwitchSession: (id: string) => void; |
| 23 | + onToggleTerminal: () => void; |
| 24 | + closeLabel: string; |
| 25 | + newTabLabel: string; |
| 26 | +}; |
| 27 | + |
| 28 | +export const TerminalHeader: React.FC<TerminalHeaderProps> = ({ |
| 29 | + sessions, |
| 30 | + activeSessionId, |
| 31 | + sessionStatuses, |
| 32 | + sessionLimit, |
| 33 | + onAddSession, |
| 34 | + onCloseSession, |
| 35 | + onSwitchSession, |
| 36 | + onToggleTerminal, |
| 37 | + closeLabel, |
| 38 | + newTabLabel |
| 39 | +}) => { |
| 40 | + return ( |
| 41 | + <div |
| 42 | + className="flex h-10 min-h-10 items-center px-2 gap-2 overflow-hidden shrink-0" |
| 43 | + style={{ |
| 44 | + borderBottom: '1px solid var(--terminal-border)', |
| 45 | + background: 'rgba(18, 18, 22, 0.98)', |
| 46 | + width: '100%', |
| 47 | + maxWidth: '100%', |
| 48 | + boxSizing: 'border-box' |
| 49 | + }} |
| 50 | + > |
| 51 | + <div className="flex-1 min-w-0 overflow-hidden"> |
| 52 | + <div className="flex items-center gap-1 overflow-x-auto no-scrollbar"> |
| 53 | + {sessions.map((session, index) => ( |
| 54 | + <SessionTab |
| 55 | + key={session.id} |
| 56 | + session={session} |
| 57 | + isActive={session.id === activeSessionId} |
| 58 | + status={sessionStatuses[session.id] || 'idle'} |
| 59 | + onSelect={() => onSwitchSession(session.id)} |
| 60 | + onClose={() => onCloseSession(session.id)} |
| 61 | + canClose={sessions.length > 1} |
| 62 | + index={index} |
| 63 | + /> |
| 64 | + ))} |
| 65 | + |
| 66 | + {sessions.length < sessionLimit && ( |
| 67 | + <button |
| 68 | + className={cn( |
| 69 | + 'flex items-center justify-center w-6 h-6 rounded-md transition-all duration-200 shrink-0', |
| 70 | + 'hover:bg-[var(--terminal-tab-hover)] text-[var(--terminal-text-muted)]', |
| 71 | + 'hover:text-[var(--terminal-accent)]' |
| 72 | + )} |
| 73 | + onClick={onAddSession} |
| 74 | + title={newTabLabel} |
| 75 | + > |
| 76 | + <Plus className="h-3.5 w-3.5" /> |
| 77 | + </button> |
| 78 | + )} |
| 79 | + </div> |
| 80 | + </div> |
| 81 | + |
| 82 | + <div className="flex items-center gap-1 shrink-0"> |
| 83 | + <div className="hidden sm:flex items-center gap-1 px-1.5 py-0.5 rounded bg-white/5"> |
| 84 | + <Zap className="h-2.5 w-2.5 text-amber-400" /> |
| 85 | + <span className="text-[9px] font-medium text-[var(--terminal-text-muted)]"> |
| 86 | + {sessions.length}/{sessionLimit} |
| 87 | + </span> |
| 88 | + </div> |
| 89 | + |
| 90 | + <Button |
| 91 | + variant="ghost" |
| 92 | + size="icon" |
| 93 | + onClick={onToggleTerminal} |
| 94 | + title={closeLabel} |
| 95 | + className={cn( |
| 96 | + 'h-6 w-6 rounded-md transition-all duration-200', |
| 97 | + 'hover:bg-red-500/10 hover:text-red-400', |
| 98 | + 'text-[var(--terminal-text-muted)]' |
| 99 | + )} |
| 100 | + > |
| 101 | + <X className="h-3.5 w-3.5" /> |
| 102 | + </Button> |
| 103 | + </div> |
| 104 | + </div> |
| 105 | + ); |
| 106 | +}; |
0 commit comments