import { Link, useLocation, useNavigate } from 'react-router-dom' import { useAuth } from '../contexts/AuthContext' import { usePermissions } from '../hooks/usePermissions' import { useState, useEffect } from 'react' const Sidebar = ({ isOpen, setIsOpen }) => { const location = useLocation() const navigate = useNavigate() const { user, logout } = useAuth() const { isAdmin, hasFullAccess, accessibleSpaces } = usePermissions() const [expandedMenus, setExpandedMenus] = useState({}) // Prüfe ob User Berechtigungsgruppen hat const hasGroups = isAdmin || hasFullAccess || (accessibleSpaces && accessibleSpaces.length > 0) // Menüpunkte - Home ist immer sichtbar, andere nur mit Gruppen const menuItems = [ { path: '/', label: 'Home', icon: '🏠', alwaysVisible: true }, { path: '/spaces', label: 'Spaces', icon: '📁', requiresGroups: true }, { path: '/audit-logs', label: 'Audit Log', icon: '📋', requiresGroups: true }, { path: '/impressum', label: 'Impressum', icon: 'ℹ️', requiresGroups: true }, ].filter(item => item.alwaysVisible || !item.requiresGroups || hasGroups) // Settings mit Unterpunkten const settingsMenu = { label: 'Settings', icon: '⚙️', path: '/settings', subItems: [ { path: '/settings/users', label: 'User', icon: '👥' }, { path: '/settings/permissions', label: 'Berechtigungen', icon: '🔐' }, { path: '/settings/providers', label: 'SSL Provider', icon: '🔒' }, ] } const profileItem = { path: '/profile', label: 'Profil', icon: '👤' } const isActive = (path) => { if (path === '/') { return location.pathname === '/' } return location.pathname.startsWith(path) } const toggleMenu = (menuPath) => { setExpandedMenus(prev => ({ ...prev, [menuPath]: !prev[menuPath] })) } const isMenuExpanded = (menuPath) => { return expandedMenus[menuPath] || false } // Automatisch Settings-Menü expandieren, wenn auf einer Settings-Seite useEffect(() => { if (location.pathname.startsWith('/settings')) { setExpandedMenus(prev => ({ ...prev, '/settings': true })) } }, [location.pathname]) return ( <> {/* Overlay for mobile */} {isOpen && (
setIsOpen(false)} /> )} {/* Sidebar */} ) } export default Sidebar