'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 _BaseComponent2 = require('../BaseComponent');

var _BaseComponent3 = _interopRequireDefault(_BaseComponent2);

var _classnames = require('classnames');

var _classnames2 = _interopRequireDefault(_classnames);

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

var _Icon2 = _interopRequireDefault(_Icon);

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 AppNavItem = function (_BaseComponent) {
  _inherits(AppNavItem, _BaseComponent);

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

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

    _this.state = {
      selected: _this.props.selected
    };
    _this._handleClick = _this._handleClick.bind(_this);
    return _this;
  }

  _createClass(AppNavItem, [{
    key: '_handleClick',
    value: function _handleClick(e) {
      if (!this.props.cancelSelect && this.props.onClick) {
        this.props.onClick(e);
      }
    }
  }, {
    key: 'shouldComponentUpdate',
    value: function shouldComponentUpdate(nextProps, nextState) {
      return nextProps.selected !== this.props.selected || nextProps.onlyShowIcon !== this.props.onlyShowIcon;
    }
  }, {
    key: 'render',
    value: function render() {
      var _props = this.props,
          label = _props.label,
          icon = _props.icon,
          id = _props.id,
          item = _props.item,
          items = _props.items,
          style = _props.style,
          selected = _props.selected,
          collapsed = _props.collapsed,
          overflowed = _props.overflowed,
          emptyIcon = _props.emptyIcon,
          emptyLabel = _props.emptyLabel,
          empty = _props.empty,
          dropdown = _props.dropdown,
          onlyShowIcon = _props.onlyShowIcon,
          onClick = _props.onClick,
          children = _props.children;


      var baseClasses = (0, _classnames2.default)('px-app-nav-item', { 'selected': selected }, { 'collapsed': collapsed }, { 'overflowed': overflowed }, { 'only-show-icon': onlyShowIcon });

      var iconClasses = (0, _classnames2.default)('app-nav-item__icon', { 'app-nav-item__icon--with-label': label });

      return _react2.default.createElement(
        'div',
        { onClick: this._handleClick, className: baseClasses, style: style, 'data-id': id },
        icon && _react2.default.createElement(_Icon2.default, { size: 32, icon: icon, className: iconClasses }),
        emptyIcon && _react2.default.createElement('div', { className: 'app-nav-item__icon app-nav-item__icon--with-label app-nav-item__icon--empty' }),
        emptyLabel && _react2.default.createElement('div', { className: 'app-nav-item__label app-nav-item__label--empty' }),
        label && _react2.default.createElement(
          'span',
          { className: 'app-nav-item__label' },
          label
        ),
        empty && _react2.default.createElement('div', { className: 'app-nav-item__icon app-nav-item__icon--with-label app-nav-item__icon--empty' }),
        empty && _react2.default.createElement('div', { className: 'app-nav-item__label app-nav-item__label--empty' }),
        dropdown && _react2.default.createElement(_Icon2.default, { icon: 'px-utl:chevron', size: 16, className: 'app-nav-item__dropdown-icon' })
      );
    }
  }]);

  return AppNavItem;
}(_BaseComponent3.default);

AppNavItem.defaultProps = {
  collapsed: false,

  cancelSelect: false,

  icon: null,

  item: null,

  label: null,

  selected: false,

  dropdown: false,
  empty: false,

  emptyIcon: false,

  emptyLabel: false,

  overflowed: false,

  subitem: false,
  onClick: null,
  fixedWidth: null,
  hideDropdownIcon: false

};

AppNavItem.displayName = 'AppNavItem';

exports.default = AppNavItem;