// components/main/kabelueberwachung/kue705FO/kue705FO-Funktionen/handleButtonClick.ts
import { Dispatch } from "react";
import {
  setActiveMode,
  setSelectedSlot,
} from "../../../../../redux/slices/kueChartModeSlice";

const handleButtonClick = (
  button: "Schleife" | "TDR",
  setActiveButton: Dispatch<React.SetStateAction<"Schleife" | "TDR">>,
  setLoopTitleText: Dispatch<React.SetStateAction<string>>,
  setLoopDisplayValue: Dispatch<React.SetStateAction<number | string>>,
  schleifenwiderstand: number,
  tdrLocation: number[] | undefined,
  slotIndex: number,
  dispatch: Dispatch<any>
) => {
  // 🔥 Speichert den gewählten Slot im Redux-Store
  dispatch(setSelectedSlot(slotIndex));

  if (button === "Schleife") {
    setActiveButton("Schleife");
    setLoopTitleText("Schleifenwiderstand [kOhm]");
    setLoopDisplayValue(schleifenwiderstand);
    dispatch(setActiveMode("Schleife"));
  } else if (button === "TDR") {
    setActiveButton("TDR");
    setLoopTitleText("Entfernung [Km]");
    setLoopDisplayValue(
      tdrLocation && tdrLocation[slotIndex] !== undefined
        ? tdrLocation[slotIndex]
        : "0"
    );
    dispatch(setActiveMode("TDR"));
  }
};

export default handleButtonClick;
