'use client' import { useState } from 'react' import { useParams } from 'next/navigation' import { Component, buildTree } from './_components/types' import { ComponentTreeNode } from './_components/ComponentTreeNode' import { ComponentForm } from './_components/ComponentForm' import { ComponentLibraryModal } from './_components/ComponentLibraryModal' import { PresenceSection } from './_components/PresenceSection' import { useComponents } from './_hooks/useComponents' export default function ComponentsPage() { const params = useParams() const projectId = params.projectId as string const { loading, components, handleSubmit, handleDelete, handleAddFromLibrary, setPresence, setCEMarked } = useComponents(projectId) // Split auto-detected components by presence so the expert can review the // engine's best-effort negation verdicts and move items in both directions. const present = components.filter((c) => !c.presence_status || c.presence_status === 'vorhanden') const negated = components.filter((c) => c.presence_status === 'nicht_vorhanden') const deleted = components.filter((c) => c.presence_status === 'geloescht') const tree = buildTree(present) const [showForm, setShowForm] = useState(false) const [editingComponent, setEditingComponent] = useState(null) const [addingParentId, setAddingParentId] = useState(null) const [showLibrary, setShowLibrary] = useState(false) function handleEdit(component: Component) { setEditingComponent(component) setAddingParentId(null) setShowForm(true) } function handleAddChild(parentId: string) { setAddingParentId(parentId) setEditingComponent(null) setShowForm(true) } function resetForm() { setShowForm(false) setEditingComponent(null) setAddingParentId(null) } if (loading) { return (
) } return (
{/* Header */}

Komponenten

Erfassen Sie alle Software-, Firmware-, KI- und Hardware-Komponenten der Maschine.

{!showForm && (
)}
{showLibrary && ( { setShowLibrary(false); await handleAddFromLibrary(comps, energy) }} onClose={() => setShowLibrary(false)} /> )} {showForm && ( { const ok = await handleSubmit(data, editingComponent?.id) if (ok) resetForm() }} onCancel={resetForm} initialData={editingComponent} parentId={addingParentId} /> )} {tree.length > 0 ? (
Typ Name Beschreibung Aktionen
{tree.map((component) => ( setPresence(id, 'nicht_vorhanden')} onToggleCE={setCEMarked} /> ))}
) : ( !showForm && (

Keine Komponenten erfasst

Beginnen Sie mit der Erfassung aller relevanten Komponenten Ihrer Maschine. Erstellen Sie eine hierarchische Struktur aus Software, Firmware, KI-Modulen und Hardware.

) )} setPresence(id, 'vorhanden') }, { label: 'Loeschen', variant: 'danger', onClick: handleDelete }, ]} /> setPresence(id, 'vorhanden') }, ]} />
) }