"use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

exports.__esModule = true;
exports.default = void 0;

var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));

var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));

var _react = _interopRequireWildcard(require("react"));

var _propTypes = _interopRequireDefault(require("prop-types"));

var _Ripple = _interopRequireDefault(require("../Ripple"));

var _SafeAnchor = _interopRequireDefault(require("../SafeAnchor"));

var _utils = require("../utils");

var defaultProps = {
  classPrefix: 'nav-item',
  as: _SafeAnchor.default,
  tabIndex: 0
};

var NavItem = /*#__PURE__*/_react.default.forwardRef(function (props, ref) {
  var Component = props.as,
      active = props.active,
      disabled = props.disabled,
      eventKey = props.eventKey,
      className = props.className,
      classPrefix = props.classPrefix,
      style = props.style,
      children = props.children,
      icon = props.icon,
      tabIndex = props.tabIndex,
      hasTooltip = props.hasTooltip,
      divider = props.divider,
      panel = props.panel,
      onClick = props.onClick,
      onSelect = props.onSelect,
      rest = (0, _objectWithoutPropertiesLoose2.default)(props, ["as", "active", "disabled", "eventKey", "className", "classPrefix", "style", "children", "icon", "tabIndex", "hasTooltip", "divider", "panel", "onClick", "onSelect"]);
  var handleClick = (0, _react.useCallback)(function (event) {
    if (!disabled) {
      onSelect === null || onSelect === void 0 ? void 0 : onSelect(eventKey, event);
      onClick === null || onClick === void 0 ? void 0 : onClick(event);
    }
  }, [disabled, onSelect, eventKey, onClick]);

  var _useClassNames = (0, _utils.useClassNames)(classPrefix),
      withClassPrefix = _useClassNames.withClassPrefix,
      merge = _useClassNames.merge,
      prefix = _useClassNames.prefix;

  var classes = merge(className, withClassPrefix({
    active: active,
    disabled: disabled
  }));

  if (divider) {
    return /*#__PURE__*/_react.default.createElement("div", {
      ref: ref,
      role: "separator",
      style: style,
      className: merge(className, prefix('divider'))
    });
  }

  if (panel) {
    return /*#__PURE__*/_react.default.createElement("div", {
      ref: ref,
      style: style,
      className: merge(className, prefix('panel'))
    }, children);
  }

  var item = /*#__PURE__*/_react.default.createElement(Component, (0, _extends2.default)({
    "aria-selected": active
  }, rest, {
    tabIndex: tabIndex,
    disabled: Component === _SafeAnchor.default ? disabled : null,
    className: classes,
    onClick: handleClick,
    ref: ref,
    style: style
  }), icon, children, /*#__PURE__*/_react.default.createElement(_Ripple.default, null));

  return hasTooltip ? (0, _utils.appendTooltip)({
    children: item,
    message: children,
    placement: 'right'
  }) : item;
});

NavItem.defaultProps = defaultProps;
NavItem.displayName = 'NavItem';
NavItem.propTypes = {
  as: _propTypes.default.elementType,
  active: _propTypes.default.bool,
  disabled: _propTypes.default.bool,
  className: _propTypes.default.string,
  classPrefix: _propTypes.default.string,
  divider: _propTypes.default.bool,
  panel: _propTypes.default.bool,
  onClick: _propTypes.default.func,
  style: _propTypes.default.object,
  icon: _propTypes.default.node,
  onSelect: _propTypes.default.func,
  children: _propTypes.default.node,
  eventKey: _propTypes.default.any,
  tabIndex: _propTypes.default.number,
  hasTooltip: _propTypes.default.bool
};
var _default = NavItem;
exports.default = _default;