import { connect } from 'react-redux';
import MainMenu from '../components/MainMenu';
import { toggle_menu, toggle_dashboard } from '../actions'

const mapStateToProps = (state) => ({
    show: state.ui.showMenu,
    showDashboard: state.ui.showDashboard,
    permissions: (function() {
        let p = sessionStorage.getItem('permissions');
        if (!p) return {};
        let json = {};
        try {
            json = JSON.parse(p);
        } catch (e) {
            return {};
        }
        return json
    }())
});

const mapDispatchToProps = (dispatch, ownProps) => ({
    toggleMenu: (flag) => {
        dispatch(toggle_menu(flag));
    },
    toggleDashboard: (flag) => {
        dispatch(toggle_dashboard(flag));
    }
});

export default connect(mapStateToProps, mapDispatchToProps)(MainMenu);