'use strict';

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

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 _classnames = require('classnames');

var _classnames2 = _interopRequireDefault(_classnames);

var _BaseComponent2 = require('../BaseComponent');

var _BaseComponent3 = _interopRequireDefault(_BaseComponent2);

var _Icon = require('../IconSet/Icon');

var _Icon2 = _interopRequireDefault(_Icon);

var _pxAppNavItem = require('./px-app-nav-item');

var _pxAppNavItem2 = _interopRequireDefault(_pxAppNavItem);

var _pxAppNavSubItem = require('./px-app-nav-sub-item');

var _pxAppNavSubItem2 = _interopRequireDefault(_pxAppNavSubItem);

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; }

var AppNavSubGroup = function (_BaseComponent) {
  _inherits(AppNavSubGroup, _BaseComponent);

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

    var _this = _possibleConstructorReturn(this, (AppNavSubGroup.__proto__ || Object.getPrototypeOf(AppNavSubGroup)).call(this, props, { displayName: 'AppNavSubGroup' }));

    _this.state = {
      opened: props.opened || false
    };
    return _this;
  }

  _createClass(AppNavSubGroup, [{
    key: '_handleClick',
    value: function _handleClick(e, item, isChild) {
      this.setState({ opened: !this.state.opened });
      if (this.props.onClick) {
        this.props.onClick(item, isChild);
      }
    }
  }, {
    key: 'render',
    value: function render() {
      var _this2 = this;

      var opened = this.state.opened;

      var subgroupClasses = (0, _classnames2.default)('px-app-nav-sub-group', { 'px-app-nav-sub-group--opened': opened });
      var dropdownClasses = (0, _classnames2.default)('app-nav-subgroup__dropdown', { 'app-nav-subgroup__dropdown--open': opened });
      var _props = this.props,
          onClick = _props.onClick,
          children = _props.children,
          icon = _props.icon,
          item = _props.item,
          label = _props.label,
          selected = _props.selected,
          overflowed = _props.overflowed,
          collapsed = _props.collapsed,
          onlyShowIcon = _props.onlyShowIcon,
          emptyIcon = _props.emptyIcon;


      return _react2.default.createElement(
        'div',
        { className: subgroupClasses },
        _react2.default.createElement(_pxAppNavItem2.default, {
          dropdown: true,
          onClick: this._handleClick.bind(this, item),
          item: item,
          label: label,
          selected: selected,
          overflowed: overflowed,
          collapsed: collapsed,
          onlyShowIcon: onlyShowIcon,
          emptyIcon: emptyIcon,
          icon: icon
        }),
        _react2.default.createElement(
          'div',
          { className: dropdownClasses },
          _react2.default.createElement(
            'div',
            { className: 'app-nav-subgroup__dropdown__content' },
            item.children && item.children.map(function (child, index) {
              return _react2.default.createElement(_pxAppNavSubItem2.default, {
                onClick: _this2._handleClick.bind(_this2, child, true),
                key: index,
                item: child });
            })
          )
        )
      );
    }
  }]);

  return AppNavSubGroup;
}(_BaseComponent3.default);

AppNavSubGroup.displayName = 'AppNavSubGroup';
AppNavSubGroup.defaultProps = {
  selected: false,
  collapsed: false,
  overflowed: false,
  item: null,
  label: null,
  icon: null,
  emptyIcon: false,
  opened: false,
  onlyShowIcon: false
};

exports.default = AppNavSubGroup;