'use client'; import { Button } from '@/components/ui/Button'; import { Icon } from '@/components/ui/Icon'; import { cn } from '@/lib/utils'; import Link from 'next/link'; import { usePathname, useRouter } from 'next/navigation'; import React, { useEffect, useState } from 'react'; interface SidebarProps { isOpen?: boolean; onClose?: () => void; } export const Sidebar: React.FC = ({ isOpen = false, onClose, }) => { const pathname = usePathname(); const router = useRouter(); const [isSigningOut, setIsSigningOut] = useState(false); const [signOutError, setSignOutError] = useState(''); const navigation = [ { group: 'Monitoring', items: [ { name: 'Dashboard', href: '/vcon/dashboard', icon: 'LayoutDashboard' }, { name: 'Events', href: '/vcon/data', icon: 'Activity' }, ], }, { group: 'Data', items: [ { name: 'Export', href: '/vcon/export', icon: 'Download' }, { name: 'Storage', href: '/vcon/storage', icon: 'HardDrive' }, ], }, { group: 'Administration', items: [ { name: 'Clients', href: '/vcon/clients', icon: 'Key' }, { name: 'Settings', href: '/vcon/settings', icon: 'Sliders' }, ], }, { group: 'Tools', items: [ { name: 'Python SDK', href: '/vcon/sdk', icon: 'FileCode2' }, { name: 'Simulator', href: '/vcon/simulator', icon: 'Play' }, ], }, ]; const activeGroup = navigation.find((section) => section.items.some((item) => item.href === pathname) )?.group; const [openGroup, setOpenGroup] = useState(activeGroup ?? navigation[0].group); useEffect(() => { if (activeGroup) setOpenGroup(activeGroup); }, [activeGroup]); const signOut = async () => { setIsSigningOut(true); setSignOutError(''); try { const response = await fetch('/api/auth/logout', { method: 'POST' }); if (!response.ok) throw new Error('Unable to sign out. Please try again.'); router.replace('/vcon/login'); router.refresh(); } catch (error) { setSignOutError( error instanceof Error ? error.message : 'Unable to sign out. Please try again.', ); } finally { setIsSigningOut(false); } }; return ( <> {/* Mobile Backdrop */} {isOpen && (
)} {/* Sidebar Container */} ); }; export default Sidebar;