import { useEffect, useState } from 'react' import { Link, useLocation, useNavigate } from 'react-router-dom' import { useAuth } from '../context/AuthContext' import { IconTicket, IconUsers, IconTargetArrow, IconReportMoney, IconScale, IconActivityHeartbeat, IconFolders, IconLayoutGrid, IconCalendar, IconSettings, IconLogout, IconLayoutSidebarLeftCollapse, IconLayoutSidebarLeftExpand, IconExternalLink, } from '@tabler/icons-react' import { openProjectAdmin } from '../lib/employeeAdminApi' import { serverpulsApi } from '../lib/serverpulsApi' import { startsCollapsed } from '../lib/sidebar' export default function Sidebar() { const { user, logout, isAdmin } = useAuth() const navigate = useNavigate() const location = useLocation() const [collapsed, setCollapsed] = useState(() => startsCollapsed()) const [switching, setSwitching] = useState(false) const [pulseLevel, setPulseLevel] = useState('ok') // Serverpuls-Punkt: nur Admins, beim Laden und alle 5 Minuten; Fehler bleiben still useEffect(() => { if (!isAdmin) { setPulseLevel('ok'); return undefined } let dead = false const load = () => { serverpulsApi.overview() .then((o) => { if (!dead) setPulseLevel(o?.level || 'ok') }) .catch(() => { if (!dead) setPulseLevel('ok') }) } load() const iv = setInterval(load, 5 * 60 * 1000) return () => { dead = true; clearInterval(iv) } }, [isAdmin]) const handleProjectAdmin = async () => { setSwitching(true) await openProjectAdmin() } const handleLogout = async () => { await logout() navigate('/login') } // Eine flache Liste: fuer ein kleines Team reichen acht Eintraege ohne Gruppen const links = [ { label: 'Tickets', href: '/tickets', icon: }, { label: 'Planboard', href: '/planboard', icon: }, { label: 'Projekte', href: '/projects', icon: }, { label: 'Services', href: '/services', icon: }, { label: 'Kunden', href: '/customers', icon: }, // Leads liegen auf Eis (Lead-Automatik gestoppt 2026-09-30): grau, nicht klickbar { label: 'Leads', href: '/leads', icon: , paused: true }, ...(isAdmin ? [{ label: 'Finanzen', href: '/finance', also: '/finanzen', icon: }] : []), { label: 'Rechtliches', href: '/rechtliches', icon: }, ...(isAdmin ? [{ label: 'Serverpuls', href: '/serverpuls', icon: , dot: pulseLevel }] : []), ...(isAdmin ? [{ label: 'Admin', href: '/admin', icon: }] : []), ] const isActive = (href) => location.pathname === href || location.pathname.startsWith(href + '/') // Finanzen bleibt auch auf der Rueckkehrseite der Bankfreigabe (/finanzen/...) markiert const isLinkActive = (link) => isActive(link.href) || (link.also ? isActive(link.also) : false) return ( ) }