// Immutable
import { Map, List } from 'immutable';
// Constants
import * as actionTypes from '../constants/action-types';
import { PRIVILEGE } from '../constants/config.js';

const initialState = Map({
	navHeaderTitle: 'WG',
	navItems: List.of(
		Map({
			displayText: 'Dashboard',
			link: '/main'
		}),
		Map({
			displayText: 'Task',
			link: '/main/task'
		}),
		Map({
			displayText: 'PTO',
			link: '/main/pto'
		}),
		Map({
			displayText: 'Data Explorer',
			link: '/main/data-explorer'
		}),
		Map({
			displayText: 'Redux Demo',
			link: '/main/redux-demo'
		}),
    Map({
      displayText: 'Document',
      link: '/main/document'
    }),
    Map({
      displayText: 'Valid Demo',
      link: '/main/valid-demo'
    }),
    Map({
      displayText: 'Article List',
      link: '/main/article-list'
    }),
    Map({
      displayText: 'Article',
      link: '/main/article'
    }),
	),
	hasLogo: true
});

const updateNavigationItem = (state, action) => {
	return action.user.privilege >= PRIVILEGE.ADMIN ?
		state.update('navItems', (items) => {
			return items.filter(
				item => item.get('displayText') !== 'Admin'
			).unshift(
			    Map({
					displayText: 'Admin',
					link: '/main/admin'
				})
			);
		}) :
		state.update('navItems', (items) => items.filter(
			item => item.get('displayText') !== 'Admin'
		));
};

export default function mainReducer(state = initialState, action) {
	switch (action.type) {
		case actionTypes.GET_CURRENT_USER_SUCCESS:
			return updateNavigationItem(state, action);
		case actionTypes.LOGIN_SUCCESS:
			return updateNavigationItem(state, action);
		default:
			return state;
	}
};

@@ -487,32 +487,110 @@
 explorer'%0A%09%09%7D),%0A
+    Map(%7B%0A      displayText: 'Document',%0A      link: '/main/document'%0A    %7D),%0A
 %09%09Map(%7B%0A%09%09%09displ
@@ -679,290 +679,50 @@
 t: '
-Document',%0A      link: '/main/document'%0A    %7D),%0A    Map(%7B%0A      displayText: 'Valid Demo',%0A      link: '/main/valid-demo'%0A    %7D),%0A    Map(%7B%0A      displayText: 'Article List',%0A      link: '/main/article-list'%0A    %7D),%0A    Map(%7B%0A      displayText: 'Article',%0A      link: '/main/article
+Valid Demo',%0A      link: '/main/valid-demo
 '%0A  

arrange Navigator order