// compoenents/main/kabelueberwachung/kue705FO/hooks/useIsoDisplay.ts
import { useEffect, useState } from "react";
import { getAlarmDisplayText } from "../../../../../utils/alarmUtils";

const useIsoDisplay = (
  slotIndex: number,
  kuePSTmMinus96V: boolean,
  kueCableBreak: boolean,
  kueGroundFault: boolean,
  kueAlarm1: boolean,
  kueAlarm2: boolean,
  kueOverflow: boolean,
  isolationswert: number,
  isoDisplayText: string,
  groundFaultDisplayText: string,
  isoFaultDisplayText: string,
  loopFaultDisplayText: string,
  isoGreaterThan200: string
) => {
  const [isoDisplayValue, setIsoDisplayValue] = useState<
    string | JSX.Element
  >();

  useEffect(() => {
    setIsoDisplayValue(
      getAlarmDisplayText(
        slotIndex,
        [kuePSTmMinus96V ? 1 : 0],
        [kueCableBreak ? 1 : 0],
        [kueGroundFault ? 1 : 0],
        [kueAlarm1 ? 1 : 0],
        [kueAlarm2 ? 1 : 0],
        [kueOverflow ? 1 : 0],
        isolationswert,
        isoDisplayText,
        groundFaultDisplayText,
        isoFaultDisplayText,
        loopFaultDisplayText,
        isoGreaterThan200
      )
    );
  }, [
    slotIndex,
    isolationswert,
    isoDisplayText,
    groundFaultDisplayText,
    isoFaultDisplayText,
    loopFaultDisplayText,
    isoGreaterThan200,
    kuePSTmMinus96V,
    kueCableBreak,
    kueGroundFault,
    kueAlarm1,
    kueAlarm2,
    kueOverflow,
  ]);

  return isoDisplayValue;
};

export default useIsoDisplay;
