'use strict';

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

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 _react = require('react');

var _react2 = _interopRequireDefault(_react);

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

var _propTypes2 = _interopRequireDefault(_propTypes);

var _classnames = require('classnames');

var _classnames2 = _interopRequireDefault(_classnames);

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

function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }

/**
 * Menu item for navigation menu
 * @param {*} props
 */
function SideNavMenuItem(props) {
  var active = props.active,
      image = props.image,
      className = props.className,
      children = props.children,
      as = props.as,
      to = props.to,
      rest = _objectWithoutProperties(props, ['active', 'image', 'className', 'children', 'as', 'to']);

  var additionalProps = {};

  var elementReplaced = as && to; // then I'm assuming that this is a NavLink but don't want a direct class reference here
  var ElementType = as || 'div';

  if (elementReplaced) {
    additionalProps.activeClassName = 'side-nav_active';
    additionalProps.to = to;
  }
  var elementClasses = (0, _classnames2.default)('side-nav__icon-container', {
    'side-nav_active': active && !elementReplaced
  });

  return _react2.default.createElement(
    'li',
    { className: (0, _classnames2.default)('side-nav__item', className) },
    _react2.default.createElement(
      ElementType,
      _extends({
        className: elementClasses
      }, additionalProps, rest, {
        style: { width: '100%' }
      }),
      _react2.default.createElement(
        _react2.default.Fragment,
        null,
        image ? _react2.default.createElement('img', { src: image }) : null,
        children
      )
    )
  );
}

SideNavMenuItem.defaultProps = {
  active: false,
  image: ''
};

SideNavMenuItem.propTypes = {
  active: _propTypes2.default.bool,
  /** image URI */
  image: _propTypes2.default.string
};

exports.default = SideNavMenuItem;
//# sourceMappingURL=SideNavMenuItem.js.map