import { connect } from 'react-redux';
import { navigationToggle } from '../../Application/Navigation/actions';
import { overlayModalsHideAll } from '../Modal/reducer';
import Component from './component';
import { overlayShow, overlayHideAll } from './reducer';

const mapStateToProps = ({ navigation, overlay }) => {
  const { showNavigation } = navigation;
  const { activeOverlays } = overlay;

  return {
    showNavigation,
    activeOverlays,
  };
};

const mergeProps = (state, { dispatch }) => {
  const { showNavigation } = state;

  return {
    ...state,

    onOverlayOpen() {
      dispatch(overlayShow());
    },

    onOverlayHideAll() {
      dispatch(overlayHideAll());
      dispatch(overlayModalsHideAll());
      showNavigation && dispatch(navigationToggle());
    },
  };
};

export default connect(mapStateToProps, undefined, mergeProps)(Component);
