import {
    SET_PARAMS_FROM_URL,
    RESET_PARAMS,
    SET_ACTIVE_MODULE,
    SET_ACTIVE_SUB_MODULE,
    RESET_ACTIVE_SUB_MODULE
} from '../../constants/pageConstants';

const moduleReducers = {};

moduleReducers[SET_PARAMS_FROM_URL] = (state, action) => {
    return Object.assign({}, state, {
        urlParams: action.urlParams
    });
};

moduleReducers[RESET_PARAMS] = (state, action) => {
    return Object.assign({}, state, {
        urlParams: {}
    });
};

moduleReducers[SET_ACTIVE_MODULE] = (state, action) => {
    return Object.assign({}, state, {
        activeModule: action.activeModule
    });
};

moduleReducers[SET_ACTIVE_SUB_MODULE] = (state, action) => {
    return Object.assign({}, state, {
        activeSubmodule: action.activeSubmodule
    });
};

moduleReducers[RESET_ACTIVE_SUB_MODULE] = (state, action) => {
    return Object.assign({}, state, {
        activeSubmodule: ''
    });
};

const pageReducer = (state = {}, action) => {
    return moduleReducers[action.type]
        ? moduleReducers[action.type](state, action)
        : state;
};

export default pageReducer;
