import { useEffect, useRef, useState } from 'react'; import { ArrowLeftRight, ChevronUp } from 'lucide-react'; import { useLocation, useNavigate } from 'react-router-dom'; import { cn } from '@/lib/utils'; import { aiModules, getAiModuleForPath, type AiModuleId } from '@/lib/ai-modules'; const moduleToneClasses: Record = { programming: { active: 'bg-[#DCE6EF]', icon: 'bg-[#DCE6EF]' }, painting: { active: 'bg-[#DCE6EF]', icon: 'bg-[#DCE6EF]' }, }; export function ModuleSwitcher({ sidebarCollapsed }: { sidebarCollapsed: boolean }) { const location = useLocation(); const navigate = useNavigate(); const [open, setOpen] = useState(false); const switcherRef = useRef(null); const activeModuleId = getAiModuleForPath(location.pathname); useEffect(() => { if (!open) return undefined; const handleMouseDown = (event: MouseEvent) => { const target = event.target; if (target instanceof Node && !switcherRef.current?.contains(target)) { setOpen(false); } }; const handleKeyDown = (event: KeyboardEvent) => { if (event.key === 'Escape') setOpen(false); }; document.addEventListener('mousedown', handleMouseDown); document.addEventListener('keydown', handleKeyDown); return () => { document.removeEventListener('mousedown', handleMouseDown); document.removeEventListener('keydown', handleKeyDown); }; }, [open]); return (
{open ? ( ) : null}
); }