import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
import React from 'react';
import { connect } from 'react-redux';
import { getActiveNamespace } from '../../core/namespaceIntegration/selectors';
import { getSourceUserChoice, getSource, getProjectMetadata } from '../../core/dataBus/selectors';
import { toggleSwitch, selectSideBarTab } from '../../core/controlsBus/actions';
import { getCheckedState, getValuesState } from '../../core/controlsBus/selectors';
import SideBar from './component/SideBar';

var SideBarContainer = function SideBarContainer(_ref) {
  var sideBar = _ref.sideBar,
      otherProps = _objectWithoutProperties(_ref, ["sideBar"]);

  if (!sideBar) return null; //TODO: add animation slide

  return React.createElement(SideBar, otherProps);
};

var mapStateToProps = function mapStateToProps(state, props) {
  var namespace = getActiveNamespace(state);

  if (!namespace) {
    return {};
  }

  var _getSourceUserChoice = getSourceUserChoice(state, {
    namespace: namespace
  }),
      selectedNode = _getSourceUserChoice.selectedNode;

  var _getSource = getSource(state, {
    namespace: namespace
  }),
      filesMap = _getSource.filesMap;

  var _getProjectMetadata = getProjectMetadata(state, {
    namespace: namespace
  }),
      language = _getProjectMetadata.language,
      fullFeaturesSupport = _getProjectMetadata.fullFeaturesSupport;

  var _getValuesState = getValuesState(state, props),
      selectedTabInSideBar = _getValuesState.selectedTabInSideBar;

  var _getCheckedState = getCheckedState(state),
      sideBar = _getCheckedState.sideBar,
      dependenciesDiagramOn = _getCheckedState.dependenciesDiagramOn,
      codeCrumbsDiagramOn = _getCheckedState.codeCrumbsDiagramOn;

  return {
    namespace: namespace,
    language: language,
    selectedNode: selectedNode,
    filesMap: filesMap,
    sideBar: sideBar,
    dependenciesDiagramOn: dependenciesDiagramOn,
    codeCrumbsDiagramOn: codeCrumbsDiagramOn,
    selectedTabInSideBar: selectedTabInSideBar,
    fullFeaturesSupport: fullFeaturesSupport
  };
};

var mapDispatchToProps = function mapDispatchToProps(dispatch) {
  return {
    onClose: function onClose() {
      return dispatch(toggleSwitch('sideBar', false));
    },
    onTabSelect: function onTabSelect(tabIndex) {
      return dispatch(selectSideBarTab(tabIndex));
    }
  };
};

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