import React, { useState } from "react"; import { Icon } from "@iconify/react"; // Für Iconify Icons function Kue705FO({ isolationswert, // Übergabeparameter für den Isolationswert schleifenwiderstand, // Übergabeparameter für den Schleifenwiderstand modulName, // Übergabeparameter für den Modulnamen kueVersion = "V4.19", // Optionaler Parameter für die Version (Standardwert) kueOnline, // Array für den Modulstatus (1: Modul vorhanden, 0: kein Modul) slotIndex, // Der Index des Slots, für den die Anzeige gilt }) { const [activeButton, setActiveButton] = useState("Schleife"); const [displayText, setDisplayText] = useState("Schleifenwiderstand [kOhm]"); const handleButtonClick = (button) => { if (button === "Schleife") { setActiveButton("Schleife"); setDisplayText("Schleifenwiderstand [kOhm]"); } else if (button === "TDR") { setActiveButton("TDR"); setDisplayText("Entfernung [Km]"); } }; // Funktion für die Aktualisierung (TDR-Aufruf) const goTDR = () => { let slot = slotIndex + 1; // Slotnummer (index beginnt bei 0, also +1) // Bedingung: wenn der Slot größer als 32 ist, wird die Funktion beendet if (slot >= 32) { return; } // Bereite die Slot-Informationen vor let slotFormat = slot < 10 ? `0${slot}` : `${slot}`; const data = { [`KTT${slotFormat}`]: 1, slot: slot, }; const apiUrl = process.env.NEXT_PUBLIC_API_BASE_URL; fetch(`${apiUrl}/CPL?Service/KUEdetailTDR.ACP`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify(data), }) .then((response) => { if (response.ok) { console.log("POST erfolgreich gesendet für Slot", slot); } else { console.error("Fehler beim Senden der POST-Anfrage"); } }) .catch((error) => { console.error("Fehler:", error); }); }; const goLoop = () => { let slot = slotIndex + 1; if (slot >= 32) { return; } let slotFormat = slot < 10 ? `0${slot}` : `${slot}`; const data = { [`KS_${slotFormat}`]: 1, slot: slot, }; const apiUrl = process.env.NEXT_PUBLIC_API_BASE_URL; fetch(`${apiUrl}/CPL?Service/KUEdetail.HTML`, { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify(data), }) .then((response) => { if (response.ok) { console.log("POST erfolgreich gesendet für Slot", slot); } else { console.error("Fehler beim Senden der POST-Anfrage"); } }) .catch((error) => { console.error("Fehler:", error); }); }; // Überprüfe, ob ein Modul im Slot vorhanden ist const isModulPresent = kueOnline[slotIndex] === 1; // Bestimme, welche Funktion ausgeführt wird, basierend auf dem aktiven Button const handleRefreshClick = () => { if (activeButton === "Schleife") { goLoop(); // Wenn Schleife aktiv ist, starte goLoop } else if (activeButton === "TDR") { goTDR(); // Wenn TDR aktiv ist, starte goTDR } }; return (
{isModulPresent ? ( <>
{slotIndex + 1}

KÜ705-FO

Betrieb
Alarm
{isolationswert || ">200"}
ISO MOhm
{modulName || "Test1"}
{kueVersion}
{displayText}

{schleifenwiderstand || "0"} kOhm

) : (

Kein Modul im Slot {slotIndex + 1}

)}
); } export default Kue705FO;