// brushSlice.ts
import { createSlice } from "@reduxjs/toolkit";

interface BrushState {
  startIndex: number;
  endIndex: number;
  startDate: string | null;
  endDate: string | null;
  isBrushReset: boolean; // 🆕 Hinzugefügt für zuverlässigen Reset
}

const initialState: BrushState = {
  startIndex: 0,
  endIndex: 0,
  startDate: null,
  endDate: null,
  isBrushReset: false, // 🆕
};

const brushSlice = createSlice({
  name: "brush",
  initialState,
  reducers: {
    setBrushRange(state, action) {
      state.startIndex = action.payload.startIndex;
      state.endIndex = action.payload.endIndex;
      state.startDate = action.payload.startDate || state.startDate;
      state.endDate = action.payload.endDate || state.endDate;
      state.isBrushReset = false; // 🆕 Sobald Brush gesetzt wird, Reset zurücksetzen
    },
    resetBrushRange(state) {
      state.startIndex = 0;
      state.endIndex = 0;
      state.startDate = null;
      state.endDate = null;
      state.isBrushReset = true; // 🆕 Status für Reset setzen
    },
  },
});

export const { setBrushRange, resetBrushRange } = brushSlice.actions;
export default brushSlice.reducer;
