import { motion } from 'framer-motion'; import { X, Plus, MoreVertical } from 'lucide-react'; import { useTabStore } from '../../stores/tabStore'; import { getBoardTheme } from '../../lib/design-tokens'; import { useState, useRef, useEffect } from 'react'; export default function TabBar() { const tabs = useTabStore((state) => state.tabs); const activeTabId = useTabStore((state) => state.activeTabId); const setActiveTab = useTabStore((state) => state.setActiveTab); const closeTab = useTabStore((state) => state.closeTab); const openTab = useTabStore((state) => state.openTab); const closeAllTabs = useTabStore((state) => state.closeAllTabs); const closeOtherTabs = useTabStore((state) => state.closeOtherTabs); const [contextMenu, setContextMenu] = useState<{ x: number; y: number; tabId: string; } | null>(null); const contextMenuRef = useRef(null); useEffect(() => { const handleClickOutside = (e: MouseEvent) => { if (contextMenuRef.current && !contextMenuRef.current.contains(e.target as Node)) { setContextMenu(null); } }; if (contextMenu) { document.addEventListener('mousedown', handleClickOutside); return () => document.removeEventListener('mousedown', handleClickOutside); } }, [contextMenu]); const handleTabClick = (tabId: string) => { setActiveTab(tabId); }; const handleCloseTab = (e: React.MouseEvent, tabId: string) => { e.stopPropagation(); closeTab(tabId); }; const handleContextMenu = (e: React.MouseEvent, tabId: string) => { e.preventDefault(); setContextMenu({ x: e.clientX, y: e.clientY, tabId, }); }; const handleNewTab = () => { // Open a default board or show board selector openTab({ type: 'catalog', title: '/g/ - Technology', board: 'g', }); }; return ( <>
{tabs.map((tab) => { const isActive = tab.id === activeTabId; const themeColor = tab.board ? getBoardTheme(tab.board) : '#6b7280'; return ( handleTabClick(tab.id)} onContextMenu={(e) => handleContextMenu(e, tab.id)} className={`tab relative flex items-center gap-2 px-4 h-full border-r border-dark-border min-w-[120px] max-w-[200px] group ${isActive ? 'tab-active bg-dark-elevated' : 'tab-inactive' }`} whileHover={{ backgroundColor: isActive ? undefined : 'rgba(255, 255, 255, 0.05)' }} > {/* Board color indicator */} {tab.board && (
)} {/* Tab title */} {tab.title} {/* New replies indicator */} {tab.hasNewReplies && (
)} {/* Close button */} {/* Active indicator */} {isActive && ( )} ); })} {/* New Tab Button */}
{/* Context Menu */} {contextMenu && (
)} ); }