'use strict';

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

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 _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 LinkGroup = exports.LinkGroup = function (_React$Component) {
  _inherits(LinkGroup, _React$Component);

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

    var _this = _possibleConstructorReturn(this, (LinkGroup.__proto__ || Object.getPrototypeOf(LinkGroup)).call(this, props));

    _this.state = {
      sideNavState: _this.props.collapsed
    };
    return _this;
  }

  _createClass(LinkGroup, [{
    key: 'componentWillReceiveProps',
    value: function componentWillReceiveProps(nextProps) {
      if (!nextProps.expanded) {
        this.setState({ sideNavState: nextProps.collapsed });
      }
      if (nextProps.collapsed !== this.props.collapsed && !this.props.collapsed) {
        this.props.onClick(false, this.props.label);
      }
    }
  }, {
    key: 'render',
    value: function render() {
      var _this2 = this;

      var classes = (this.props.className || '') + ' vs-sidenav-entry vs-sidenav-container' + (this.props.expanded ? ' expanded' : '');
      var expandRow = function expandRow() {
        _this2.props.onClick(!_this2.props.expanded, _this2.props.label);
        if (_this2.props.expanded) {
          _this2.props.toggleSideNav(_this2.state.sideNavState);
        } else {
          _this2.props.toggleSideNav(_this2.props.expanded);
        }
      };

      var icon = !_ramda2.default.isNil(this.props.svgIcon) ? _react2.default.createElement(
        _Icons.SideNavSvgIcon,
        null,
        this.props.svgIcon
      ) : !_ramda2.default.isNil(this.props.icon) ? this.props.icon : (0, _Icons.makeDefaultIcon)(this.props.label);

      return _react2.default.createElement(
        'li',
        { className: classes },
        _react2.default.createElement(
          'a',
          {
            className: 'vs-sidenav-container-row',
            onClick: expandRow,
            title: this.props.label
          },
          _react2.default.createElement(
            'div',
            { className: 'vs-sidenav-container-row-left' },
            icon,
            _react2.default.createElement(
              'span',
              { className: 'vs-sidenav-container-label' },
              this.props.label
            )
          ),
          _react2.default.createElement('i', { className: 'fa fa-chevron-right vs-sidenav-container-chevron' })
        ),
        _react2.default.createElement(
          'ul',
          { className: 'vs-link-group-children' },
          this.props.children
        )
      );
    }
  }]);

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

LinkGroup.propTypes = {
  expanded: _propTypes2.default.bool,
  onClick: _propTypes2.default.func.isRequired,
  label: _propTypes2.default.string.isRequired,
  toggleSideNav: _propTypes2.default.func.isRequired
};