'use client' import React, { useState, useEffect, useRef, useCallback } from 'react' import Link from 'next/link' import { usePathname, useParams } from 'next/navigation' interface CEStep { step: number label: string href: string | null external?: boolean sameAs?: number note?: string } const CE_STEPS: CEStep[] = [ { step: 3, label: 'Grenzen & Verwendung', href: '/interview' }, { step: 4, label: 'Normenrecherche', href: null, external: true }, { step: 5, label: 'Komponenten', href: '/components' }, { step: 6, label: 'Gefaehrdungen', href: '/hazards' }, { step: 7, label: 'Risikobewertung', href: '/hazards', sameAs: 6 }, { step: 8, label: 'Massnahmen', href: '/mitigations' }, { step: 9, label: 'Nachweise', href: '/evidence' }, { step: 10, label: 'Restrisiko', href: '/hazards', note: 'Reassessment' }, { step: 11, label: 'Verifikation', href: '/verification' }, { step: 14, label: 'CE-Akte', href: '/tech-file' }, ] function getNavigableSteps(basePath: string): CEStep[] { return CE_STEPS.filter((s) => s.href !== null && !s.external) } export default function IACEFlowFAB() { const [isOpen, setIsOpen] = useState(false) const panelRef = useRef(null) const fabRef = useRef(null) const pathname = usePathname() const params = useParams() const projectId = params?.projectId as string const basePath = `/sdk/iace/${projectId}` const activeStepIndex = CE_STEPS.findIndex((s) => { if (!s.href) return false return pathname.startsWith(`${basePath}${s.href}`) }) const navigableSteps = getNavigableSteps(basePath) const currentNavIndex = navigableSteps.findIndex((s) => { if (!s.href) return false return pathname.startsWith(`${basePath}${s.href}`) }) const completedCount = CE_STEPS.filter((s) => s.href && !s.external).length const totalSteps = CE_STEPS.length const handleClose = useCallback(() => setIsOpen(false), []) useEffect(() => { function onKeyDown(e: KeyboardEvent) { if (e.key === 'Escape') handleClose() } function onClickOutside(e: MouseEvent) { if ( panelRef.current && !panelRef.current.contains(e.target as Node) && fabRef.current && !fabRef.current.contains(e.target as Node) ) { handleClose() } } if (isOpen) { document.addEventListener('keydown', onKeyDown) document.addEventListener('mousedown', onClickOutside) } return () => { document.removeEventListener('keydown', onKeyDown) document.removeEventListener('mousedown', onClickOutside) } }, [isOpen, handleClose]) const goPrev = () => { if (currentNavIndex > 0) { const prev = navigableSteps[currentNavIndex - 1] if (prev.href) window.location.href = `${basePath}${prev.href}` } } const goNext = () => { if (currentNavIndex < navigableSteps.length - 1) { const next = navigableSteps[currentNavIndex + 1] if (next.href) window.location.href = `${basePath}${next.href}` } } return (
{/* Expanded Panel */}
{/* Header */}

CE-Prozessschritte

{completedCount}/{totalSteps} Schritte im Tool

{/* Steps */}
{CE_STEPS.map((step, idx) => { const isActive = idx === activeStepIndex const isExternal = step.external || step.href === null const fullHref = step.href ? `${basePath}${step.href}` : null const rowContent = (
{/* Step number circle */}
{isActive ? ( ) : !isExternal ? ( ) : ( step.step )}
{/* Label */}
{step.label} {(step.note || isExternal) && ( {step.note || '(extern)'} )}
{/* Step badge */} #{step.step}
) if (fullHref && !isExternal) { return ( {rowContent} ) } return
{rowContent}
})}
{/* Prev/Next navigation */}
{currentNavIndex >= 0 ? currentNavIndex + 1 : '-'}/{navigableSteps.length}
{/* FAB Button */}
) }