function viewerReducer(state = [], action) {
    switch (action.type) {
        case 'SET_INITIAL_STATE': {
            const payload = action.payload || {};
            const newState = payload;

            return { ...state, ...newState };
        }

        case 'OPEN_SIDEBAR': {
            const payload = action.payload || {};
            const newState = {
                ...state,
                sidebar: {
                    ...state.sidebar,
                    collapsed: false,
                    selected: payload.selected
                }
            };

            return { ...state, ...newState };
        }

        case 'CLOSE_SIDEBAR': {
            const payload = action.payload || {};
            const newState = {
                ...state,
                sidebar: {
                    ...state.sidebar,
                    collapsed: true,
                    selected: undefined
                }
            };

            return { ...state, ...newState };
        }

        case 'SET_LOADING': {
            const payload = action.payload || {};
            const newState = {
                ...state,
                loading: {
                    ...state.loading,
                    isLoading: payload.isLoading,
                    message: payload.message
                }
            };

            return { ...state, ...newState };
        }

        default:
            return state;
    }
};

export default viewerReducer;