// components/main/kabelueberwachung/kue705FO/handlers/handleOpenChartModal.ts
import { Dispatch, SetStateAction } from "react";
import {
  setChartOpen,
  setSlotNumber,
} from "../../../../../redux/slices/kabelueberwachungChartSlice";
import {
  setActiveMode,
  setSelectedSlot, // ✅ Importiere setSelectedSlot
} from "../../../../../redux/slices/kueChartModeSlice";
import { useDispatch } from "react-redux";

const handleOpenChartModal = (
  setShowChartModal: Dispatch<SetStateAction<boolean>>,
  dispatch: ReturnType<typeof useDispatch>,
  slotIndex: number,
  activeButton: "Schleife" | "TDR" | "ISO"
) => {
  setShowChartModal(true);
  dispatch(setChartOpen(true));
  dispatch(setSlotNumber(slotIndex));
  console.log("SlotIndex:", slotIndex);

  // ✅ Speichert den gewählten Slot in Redux
  dispatch(setSelectedSlot(slotIndex));

  if (activeButton === "TDR") {
    dispatch(setActiveMode("TDR"));
  } else if (activeButton === "ISO") {
    dispatch(setActiveMode("ISO"));
  } else {
    dispatch(setActiveMode("Schleife"));
  }
};

export default handleOpenChartModal;
