import { useEffect, useState } from 'react'; import { NavLink, Outlet, useNavigate } from 'react-router-dom'; import { useAuth } from '../context/AuthContext.jsx'; import { api } from '../api/client.js'; import ThemeToggle from './ThemeToggle.jsx'; import logo from '../assets/logo.png'; import logoDark from '../assets/logo-dark.png'; const ICONS = { home: 'M3 11.5 12 4l9 7.5M5 10v9a1 1 0 0 0 1 1h4v-6h4v6h4a1 1 0 0 0 1-1v-9', tag: 'M4 4h7l9 9-7 7-9-9V4Zm3.5 3.5h.01', car: 'M3 13.5 4.5 9A2 2 0 0 1 6.4 7.5h11.2A2 2 0 0 1 19.5 9L21 13.5M3 13.5v4a1 1 0 0 0 1 1h1a1 1 0 0 0 1-1v-1h12v1a1 1 0 0 0 1 1h1a1 1 0 0 0 1-1v-4M3 13.5h18M6.5 16.5h.01M17.5 16.5h.01', box: 'M12 3 4 7.5v9L12 21l8-4.5v-9L12 3Zm0 9 8-4.5M12 12v9M12 12 4 7.5', mail: 'M4 6h16a1 1 0 0 1 1 1v10a1 1 0 0 1-1 1H4a1 1 0 0 1-1-1V7a1 1 0 0 1 1-1Zm0 0 8 7 8-7', users: 'M16 7a4 4 0 1 1-8 0 4 4 0 0 1 8 0Zm-4 6c-4 0-7 2-7 4.5V19h14v-1.5C19 15 16 13 12 13Z', shield: 'M12 3 4 6v6c0 4.5 3.4 7.7 8 9 4.6-1.3 8-4.5 8-9V6l-8-3Zm-1.5 9.5 4-4 1 1-5 5-2.5-2.5 1-1 1.5 1.5Z', lock: 'M6 10V8a6 6 0 1 1 12 0v2m-13 0h14a1 1 0 0 1 1 1v9a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1v-9a1 1 0 0 1 1-1Zm7 5v2', briefcase: 'M4 7h16a1 1 0 0 1 1 1v10a1 1 0 0 1-1 1H4a1 1 0 0 1-1-1V8a1 1 0 0 1 1-1Zm4 0V5a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2M3 12h18', sliders: 'M4 6h16M4 6a2 2 0 1 0 4 0 2 2 0 0 0-4 0Zm16 6H4m10 0a2 2 0 1 0 4 0 2 2 0 0 0-4 0ZM4 18h16m-12 0a2 2 0 1 0 4 0 2 2 0 0 0-4 0Z', image: 'M4 5h16a1 1 0 0 1 1 1v12a1 1 0 0 1-1 1H4a1 1 0 0 1-1-1V6a1 1 0 0 1 1-1Zm2 12 4.5-5.5L14 16l2.5-3L20 17H6ZM8 9.5a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0Z', help: 'M12 21a9 9 0 1 0 0-18 9 9 0 0 0 0 18Zm0-5.5v.01M9.5 9.25a2.5 2.5 0 1 1 3.5 2.29c-.7.32-1 .77-1 1.46v.3', }; const Icon = ({ path }) => ( ); export default function AdminLayout() { const { logout, user, hasPermission } = useAuth(); const navigate = useNavigate(); const [mobileOpen, setMobileOpen] = useState(false); const [newContactCount, setNewContactCount] = useState(0); useEffect(() => { if (!hasPermission('contact.manage')) return; api.get('/contact').then((rows) => setNewContactCount(rows.filter((r) => r.status === 'new').length)).catch(() => {}); }, []); const navGroups = [ { title: null, links: [ { to: '/admin', label: 'Dashboard', icon: 'home', end: true }, { to: '/admin/account', label: 'Mein Konto', icon: 'lock' }, ], }, { title: 'Fahrzeug-Katalog', links: [ { to: '/admin/brands', label: 'Marken', icon: 'tag', permission: 'brands.manage' }, { to: '/admin/models', label: 'Modelle', icon: 'car', permission: 'models.manage' }, { to: '/admin/packages', label: 'Pakete', icon: 'box', permission: 'packages.manage' }, ], }, { title: 'Website', links: [ { to: '/admin/services', label: 'Leistungen', icon: 'briefcase', permission: 'services.manage' }, { to: '/admin/faqs', label: 'FAQ', icon: 'help', permission: 'content.manage' }, ], }, { title: 'Bildergalerie', links: [ { to: '/admin/gallery-brands', label: 'Marken', icon: 'tag', permission: 'gallery.manage' }, { to: '/admin/gallery-projects', label: 'Projekte', icon: 'image', permission: 'gallery.manage' }, ], }, { title: 'Kunden', links: [ { to: '/admin/contact-requests', label: 'Kontaktanfragen', icon: 'mail', permission: 'contact.manage', badge: newContactCount }, ], }, { title: 'Verwaltung', links: [ { to: '/admin/users', label: 'Benutzer', icon: 'users', permission: 'users.manage' }, { to: '/admin/permission-groups', label: 'Berechtigungsgruppen', icon: 'shield', permission: 'permission_groups.manage' }, { to: '/admin/settings', label: 'Einstellungen', icon: 'sliders', permission: 'settings.manage' }, ], }, ] .map((group) => ({ ...group, links: group.links.filter((l) => !l.permission || hasPermission(l.permission)) })) .filter((group) => group.links.length > 0); const handleLogout = async () => { await logout(); navigate('/admin/login'); }; const linkClass = ({ isActive }) => `flex items-center justify-between gap-2 rounded-md px-3 py-2 text-sm font-medium transition ${ isActive ? 'bg-brand-500 text-white' : 'text-neutral-600 hover:bg-neutral-100 dark:text-neutral-300 dark:hover:bg-neutral-800' }`; const NavLinks = ({ onNavigate }) => ( ); return (
Angemeldet als {user?.username}{user?.is_super_admin ? ' · Super-Admin' : ''}