'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.SideNav = undefined;

var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _propTypes = require('prop-types');

var _propTypes2 = _interopRequireDefault(_propTypes);

var _reactResponsive = require('react-responsive');

var _reactResponsive2 = _interopRequireDefault(_reactResponsive);

var _ramda = require('ramda');

var _ramda2 = _interopRequireDefault(_ramda);

var _Icons = require('./Icons');

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } /** @prettier */


var SideNav = exports.SideNav = function (_React$Component) {
  _inherits(SideNav, _React$Component);

  function SideNav() {
    _classCallCheck(this, SideNav);

    return _possibleConstructorReturn(this, (SideNav.__proto__ || Object.getPrototypeOf(SideNav)).apply(this, arguments));
  }

  _createClass(SideNav, [{
    key: 'render',
    value: function render() {
      var _this2 = this;

      return _react2.default.createElement(
        _reactResponsive2.default,
        { maxWidth: 1224 },
        function (matches) {
          return _react2.default.createElement(
            SideNavP,
            _extends({ matches: matches }, _this2.props),
            _this2.props.children
          );
        }
      );
    }
  }]);

  return SideNav;
}(_react2.default.Component);

var SideNavP = function (_React$Component2) {
  _inherits(SideNavP, _React$Component2);

  function SideNavP(props) {
    _classCallCheck(this, SideNavP);

    var _this3 = _possibleConstructorReturn(this, (SideNavP.__proto__ || Object.getPrototypeOf(SideNavP)).call(this, props));

    _this3.state = {
      sideNavPreviousState: _this3.props.initializedCollapsed || _this3.props.matches
    };
    return _this3;
  }

  _createClass(SideNavP, [{
    key: 'componentWillMount',
    value: function componentWillMount() {
      this.props.onClick(this.props.initializedCollapsed || this.props.matches);
    }
  }, {
    key: 'componentWillReceiveProps',
    value: function componentWillReceiveProps(nextProps) {
      var resizePage = _ramda2.default.not(_ramda2.default.equals(this.props.matches, nextProps.matches));
      if (resizePage) {
        this.setState({
          sideNavPreviousState: nextProps.collapsed
        });
        var resizeVar = !nextProps.matches && this.state.sideNavPreviousState ? nextProps.collapsed : nextProps.matches;
        this.props.onClick(resizeVar);
      }
    }
  }, {
    key: 'render',
    value: function render() {
      var _props = this.props,
          logoBackground = _props.logoBackground,
          appName = _props.appName,
          onClick = _props.onClick,
          collapsed = _props.collapsed,
          children = _props.children,
          userMenu = _props.userMenu;


      var logoBg = logoBackground ? logoBackground : 'transparent';
      var toggle = function toggle() {
        return onClick(!collapsed);
      };
      var capAppName = appName ? appName.toUpperCase() : '';
      var userMenuWithColor = userMenu ? _react2.default.cloneElement(userMenu, { color: "#49c5b1" }) : null;
      return _react2.default.createElement(
        'ul',
        { className: 'vs-sidenav' + (collapsed ? ' collapsed' : ' active') },
        _react2.default.createElement(
          'li',
          { className: 'vs-sideNav-left-logo' },
          _react2.default.createElement(
            'div',
            { className: 'vs-sidenav-container-row' },
            _react2.default.createElement(
              'div',
              { className: 'vs-logo' },
              this.props.logo
            ),
            _react2.default.createElement(
              'span',
              { className: 'vs-app-name' },
              capAppName
            )
          )
        ),
        children,
        userMenuWithColor,
        _react2.default.createElement(
          'li',
          { className: 'vs-toggle-icon' },
          _react2.default.createElement(_Icons.ToggleIcon, { onClick: toggle, sideNavState: collapsed })
        )
      );
    }
  }]);

  return SideNavP;
}(_react2.default.Component);

SideNav.propTypes = {
  active: _propTypes2.default.bool
};