import { createSlice, PayloadAction } from "@reduxjs/toolkit";

interface ChartDataState {
  data: any[];
  activeMode: "Schleife" | "TDR"; // 🔥 Neuer Zustand für den aktiven Modus
}

const initialState: ChartDataState = {
  data: [],
  activeMode: "Schleife", // Standard ist Schleife
};

export const chartDataSlice = createSlice({
  name: "chartData",
  initialState,
  reducers: {
    setChartData: (state, action: PayloadAction<any[]>) => {
      state.data = action.payload;
    },
    clearChartData: (state) => {
      state.data = [];
    },
    setActiveMode: (state, action: PayloadAction<"Schleife" | "TDR">) => {
      state.activeMode = action.payload; // 🔥 Speichert den Modus (Schleife oder TDR)
    },
  },
});

export const { setChartData, clearChartData, setActiveMode } =
  chartDataSlice.actions;
export default chartDataSlice.reducer;
