// redux/slices/mapLayersSlice.js
import { createSlice } from "@reduxjs/toolkit";

const initialState = {
  TALAS: true,
  ECI: true,
  ULAF: true,
  GSMModem: true,
  CiscoRouter: true,
  WAGO: true,
  Siemens: true,
  OTDR: true,
  WDM: true,
  GMA: true,
  Messstellen: true,
  TALASICL: true,
  DAUZ: true,
  SMSFunkmodem: true, // ✅ Hier sicherstellen, dass es existiert
  TKKomponenten: true, // ✅ Hier sicherstellen, dass es existiert
  Sonstige: true,
};

const mapLayersSlice = createSlice({
  name: "mapLayers",
  initialState,
  reducers: {
    toggleLayer: (state, action) => {
      const layer = action.payload;
      if (state[layer] !== undefined) {
        state[layer] = !state[layer]; // Toggle Sichtbarkeit
      }
    },
    setLayerVisibility: (state, action) => {
      const { layer, visibility } = action.payload;
      if (state[layer] !== undefined) {
        state[layer] = visibility;
      }
    },
  },
});

export const { toggleLayer, setLayerVisibility } = mapLayersSlice.actions;
export const selectMapLayersState = (state) => state.mapLayers || initialState;
export default mapLayersSlice.reducer;
