"use client"; import { useEffect, useState } from "react"; import { Fragment } from "react"; import { getCircuitTree } from "../utils/api"; import type { CircuitTreeCircuitDto, CircuitTreeResponseDto } from "../types"; import { formatValue, getCircuitSectionLabel, } from "../utils/circuit-grid-model"; function renderCircuitSummaryLabel(circuit: CircuitTreeCircuitDto) { if (circuit.displayName?.trim()) { return circuit.displayName; } if (circuit.deviceRows.length > 1) { return `${circuit.deviceRows.length} Geräte`; } return "Reserve"; } export function CircuitTreePreview(props: { projectId: string; circuitListId: string }) { const { projectId, circuitListId } = props; const [data, setData] = useState(null); const [isLoading, setIsLoading] = useState(true); const [error, setError] = useState(null); useEffect(() => { setIsLoading(true); setError(null); getCircuitTree(projectId, circuitListId) .then(setData) .catch((err: unknown) => setError(err instanceof Error ? err.message : "Die Stromkreisstruktur konnte nicht geladen werden.") ) .finally(() => setIsLoading(false)); }, [projectId, circuitListId]); if (isLoading) { return
Stromkreisstruktur wird geladen …
; } if (error) { return
{error}
; } if (!data || !data.sections.length) { return
Keine Bereiche oder Stromkreise vorhanden.
; } const hasAnyCircuits = data.sections.some((section) => section.circuits.length > 0); if (!hasAnyCircuits) { return
Bereiche sind vorhanden, enthalten aber noch keine Stromkreise.
; } return (
{data.sections.map((section) => ( ))}
Betriebsmittelkennzeichen Anzeigename Phasenart Anschlussart Kostengruppe Kategorie Ebene Raumnummer Raumname Anzahl Leistung / Gerät [kW] Gleichzeitigkeit cos φ Gesamtsumme [kW] Schutzart Bemessungsstrom Charakteristik Kabeltyp Kabelquerschnitt Kabellänge Bemerkung
); } function SectionRows(props: { section: CircuitTreeResponseDto["sections"][number] }) { const { section } = props; return ( <> {getCircuitSectionLabel(section)} {section.circuits.map((circuit) => { if (circuit.deviceRows.length === 0) { return ( {circuit.equipmentIdentifier} {circuit.displayName?.trim() || "Reserve"} - {formatValue(circuit.circuitTotalPower, "circuitTotalPower")} {circuit.protectionDevice?.type ?? "-"} {formatValue(circuit.protectionDevice?.ratedCurrentA, "protectionRatedCurrent")} {circuit.protectionDevice?.tripCharacteristic ?? circuit.protectionDevice?.fuseUtilizationCategory ?? "-"} {circuit.cableType ?? "-"} {circuit.cableCrossSection ?? "-"} {formatValue(circuit.cableLength, "cableLength")} {circuit.remark ?? "-"} ); } if (circuit.deviceRows.length === 1) { const row = circuit.deviceRows[0]; return ( {circuit.equipmentIdentifier} {row.displayName || row.name} {formatValue(row.phaseType ?? undefined, "phaseType")} {row.connectionKind ?? "-"} {row.costGroup ?? "-"} {row.category ?? "-"} {row.level ?? "-"} {row.roomNumberSnapshot ?? "-"} {row.roomNameSnapshot ?? "-"} {formatValue(row.quantity, "quantity")} {formatValue(row.powerPerUnit, "powerPerUnit")} {formatValue(row.simultaneityFactor, "simultaneityFactor")} {formatValue(row.cosPhi, "cosPhi")} {formatValue(row.rowTotalPower, "rowTotalPower")} {circuit.protectionDevice?.type ?? "-"} {formatValue(circuit.protectionDevice?.ratedCurrentA, "protectionRatedCurrent")} {circuit.protectionDevice?.tripCharacteristic ?? circuit.protectionDevice?.fuseUtilizationCategory ?? "-"} {circuit.cableType ?? "-"} {circuit.cableCrossSection ?? "-"} {formatValue(circuit.cableLength, "cableLength")} {row.remark ?? circuit.remark ?? "-"} ); } return ( {circuit.equipmentIdentifier} {renderCircuitSummaryLabel(circuit)} - {formatValue(circuit.circuitTotalPower, "circuitTotalPower")} {circuit.protectionDevice?.type ?? "-"} {formatValue(circuit.protectionDevice?.ratedCurrentA, "protectionRatedCurrent")} {circuit.protectionDevice?.tripCharacteristic ?? circuit.protectionDevice?.fuseUtilizationCategory ?? "-"} {circuit.cableType ?? "-"} {circuit.cableCrossSection ?? "-"} {formatValue(circuit.cableLength, "cableLength")} {circuit.remark ?? "-"} {circuit.deviceRows.map((row) => ( {row.displayName || row.name} {formatValue(row.phaseType ?? undefined, "phaseType")} {row.connectionKind ?? "-"} {row.costGroup ?? "-"} {row.category ?? "-"} {row.level ?? "-"} {row.roomNumberSnapshot ?? "-"} {row.roomNameSnapshot ?? "-"} {formatValue(row.quantity, "quantity")} {formatValue(row.powerPerUnit, "powerPerUnit")} {formatValue(row.simultaneityFactor, "simultaneityFactor")} {formatValue(row.cosPhi, "cosPhi")} {formatValue(row.rowTotalPower, "rowTotalPower")} - - - - - - {row.remark ?? "-"} ))} ); })} -frei- Freie Zeile ); }