import { createReducer } from "redux-create-reducer";
import * as clone from "lodash/cloneDeep";
import {
    INITIALIZE,
    SWITCH,
} from "./actions";
import { ITabState } from "./";

const initialState = {};

export default createReducer(initialState, {
    [INITIALIZE](state: IContainerModule<ITabState>, action) {
        const { id, currentTab } = action.payload;
        if (!id || state[id]) {
            return state;
        }
        const clonedState = clone(state);
        clonedState[id] = {
            currentTab,
        };
        return clonedState;
    },
    [SWITCH](state: IContainerModule<ITabState>, action) {
        const { id, tabId } = action.payload;
        if (!id || !state[id]) {
            return state;
        }
        const clonedState = clone(state);
        clonedState[id] = {
            currentTab: tabId,
        };
        return clonedState;
    },
});
import { IContainerModule } from "../types";