import { useState, useRef, useEffect, type Dispatch, type SetStateAction } from 'react'; import { MessageSquare, Folder, Terminal, GitBranch, ClipboardCheck, Ellipsis, Puzzle, Box, Database, Globe, Wrench, Zap, BarChart3, type LucideIcon, } from 'lucide-react'; import { useTasksSettings } from '../../contexts/TasksSettingsContext'; import { usePlugins } from '../../contexts/PluginsContext'; import { AppTab } from '../../types/app'; const PLUGIN_ICON_MAP: Record = { Puzzle, Box, Database, Globe, Terminal, Wrench, Zap, BarChart3, Folder, MessageSquare, GitBranch, }; type CoreTabId = Exclude; type CoreNavItem = { id: CoreTabId; icon: LucideIcon; label: string; }; type MobileNavProps = { activeTab: AppTab; setActiveTab: Dispatch>; isInputFocused: boolean; }; export default function MobileNav({ activeTab, setActiveTab, isInputFocused }: MobileNavProps) { const { tasksEnabled, isTaskMasterInstalled } = useTasksSettings(); const shouldShowTasksTab = Boolean(tasksEnabled && isTaskMasterInstalled); const { plugins } = usePlugins(); const [moreOpen, setMoreOpen] = useState(false); const moreRef = useRef(null); const enabledPlugins = plugins.filter((p) => p.enabled); const hasPlugins = enabledPlugins.length > 0; const isPluginActive = activeTab.startsWith('plugin:'); // Close the menu on outside tap useEffect(() => { if (!moreOpen) return; const handleTap = (e: PointerEvent) => { const target = e.target; if (moreRef.current && target instanceof Node && !moreRef.current.contains(target)) { setMoreOpen(false); } }; document.addEventListener('pointerdown', handleTap); return () => document.removeEventListener('pointerdown', handleTap); }, [moreOpen]); // Close menu when a plugin tab is selected const selectPlugin = (name: string) => { const pluginTab = `plugin:${name}` as AppTab; setActiveTab(pluginTab); setMoreOpen(false); }; const baseCoreItems: CoreNavItem[] = [ { id: 'chat', icon: MessageSquare, label: 'Chat' }, { id: 'shell', icon: Terminal, label: 'Shell' }, { id: 'files', icon: Folder, label: 'Files' }, { id: 'git', icon: GitBranch, label: 'Git' }, ]; const coreItems: CoreNavItem[] = shouldShowTasksTab ? [...baseCoreItems, { id: 'tasks', icon: ClipboardCheck, label: 'Tasks' }] : baseCoreItems; return (
{coreItems.map((item) => { const Icon = item.icon; const isActive = activeTab === item.id; return ( ); })} {/* "More" button — only shown when there are enabled plugins */} {hasPlugins && (
{/* Popover menu */} {moreOpen && (
{enabledPlugins.map((p) => { const Icon = PLUGIN_ICON_MAP[p.icon] || Puzzle; const isActive = activeTab === `plugin:${p.name}`; return ( ); })}
)}
)}
); }