'use client'; import Link from 'next/link'; import { usePathname } from 'next/navigation'; import { useEffect, useState } from 'react'; import { ChevronDown } from 'lucide-react'; import { proconNavigation } from '@/_config/procon-navigation'; interface NavigationItem { label: string; href?: string; children?: NavigationItem[] } interface NavigationGroup { id: string; label: string; items: NavigationItem[] } const groups: NavigationGroup[] = [ { id: 'anlage', label: 'Anlage', items: [ { label: 'Anlagenübersicht', href: '/' }, { label: 'Anlage auswählen', href: '/alt/rk/anlagen' }, { label: 'Neue Anlage', href: '/alt/rk/anlagen/new' }, { label: 'Gruppen', href: '/groups' }, { label: 'Units', href: '/units' }, { label: 'Anlagen-PDF', href: '/anlagen/pdf' }, { label: 'EA’s', href: '/signals' }, { label: 'IO-Übersicht', href: '/ios' }, { label: 'Datensicherung', href: '/datensicherung' }, ] }, { id: 'import', label: 'Import', items: [ { label: 'IO Import', href: '/signals/import' }, ] }, { id: 'sps', label: 'SPS', items: [ { label: 'SPS-Exporte', href: '/sps' }, { label: 'OPC UA', href: '/sps/opcua' }, { label: 'E/A-Diagnose', href: '/sps/io-diagnose' }, { label: 'E/A-Simulation', href: '/sps/simulation' }, { label: 'OPC-Strukturen', href: '/sps/opcua-strukturen' }, { label: 'Motor-OPC-Zuordnung', href: '/motor-opc' }, { label: 'Digitalsensoren Live', href: '/sensoren-digital/live' }, { label: 'Aggregate', href: '/sps/aggregate' }, { label: 'Sensoren Digital', href: '/sps/sensoren-digital' }, { label: 'Sensoren Analog', href: '/sps/sensoren-analog' }, ] }, { id: 'procon', label: 'ProCon', items: [ { label: 'ProCon-Übersicht', href: '/procon' }, ...proconNavigation, ] }, { id: 'visualisierung', label: 'Visualisierung', items: [ { label: 'Web-Visu', href: '/visualisierung' }, { label: 'Live-Anlagenansicht', href: '/live-anlage' }, { label: 'Grafikbibliothek', href: '/visualisierung/bibliothek' }, { label: 'VisuAggregate', href: '/visu-aggregate', children: [ { label: 'Grafikübersicht', href: '/visu-aggregate/grafiken' }, ] }, { label: 'Positionstabelle', href: '/procon/positionen' }, { label: 'Zuordnung Aggregate', href: '/procon/zuordnung' }, { label: 'Zuordnung Signale Analog' }, { label: 'Zuordnung Signale Digital', href: '/sensoren-digital/bearbeiten' }, ] }, ]; export default function AppSidebar() { const pathname = usePathname(); const [expanded, setExpanded] = useState>({}); // Only the most specific route is active, including on detail and export pages. const flatten = (items: NavigationItem[]): NavigationItem[] => items.flatMap(item => [item, ...flatten(item.children ?? [])]); const active = [...groups.flatMap(group => flatten(group.items)), { label: 'Alt', href: '/alt' }] .filter(item => item.href && (pathname === item.href || item.href !== '/' && pathname.startsWith(item.href + '/'))) .sort((a, b) => b.href!.length - a.href!.length)[0]?.href; const activeGroup = groups.find(group => flatten(group.items).some(item => item.href === active))?.id; useEffect(() => { if (activeGroup) setExpanded(current => ({ ...current, [activeGroup]: true })); }, [activeGroup, pathname]); function navigationLink(item: NavigationItem) { if (!item.href) return {item.label}Geplant ; const selected = active === item.href; return {item.label} ; } function navigationEntry(item: NavigationItem) { return
  • {navigationLink(item)} {item.children && }
  • ; } return ; }