// 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"
) => {
  setShowChartModal(true);
  dispatch(setChartOpen(true));
  dispatch(setSlotNumber(slotIndex + 1));

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

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

export default handleOpenChartModal;
