import { createSlice } from '@reduxjs/toolkit';

const navigationSlice = createSlice({
  name: 'navigation',
  initialState: {
    selectedTab: "tree",
    expandedNodes: {}
  },
  reducers: {
    setSelectedTab: (state, action) => {
      state.selectedTab = action.payload;
    },
    toggleNodeExpansion: (state, action) => {
      const nodeId = action.payload;
      state.expandedNodes[nodeId] = !state.expandedNodes[nodeId];
    },
    setExpandedNodes: (state, action) => {
      state.expandedNodes = action.payload;
    }
  }
});

export const { setSelectedTab, toggleNodeExpansion, setExpandedNodes } = navigationSlice.actions;
export default navigationSlice.reducer;