import _extends from "@babel/runtime/helpers/esm/extends";
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
import React, { useCallback } from 'react';
import PropTypes from 'prop-types';
import Ripple from '../Ripple';
import SafeAnchor from '../SafeAnchor';
import { useClassNames, appendTooltip } from '../utils';
var defaultProps = {
  classPrefix: 'nav-item',
  as: SafeAnchor,
  tabIndex: 0
};
var NavItem = /*#__PURE__*/React.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 = _objectWithoutPropertiesLoose(props, ["as", "active", "disabled", "eventKey", "className", "classPrefix", "style", "children", "icon", "tabIndex", "hasTooltip", "divider", "panel", "onClick", "onSelect"]);

  var handleClick = 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 = 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.createElement("div", {
      ref: ref,
      role: "separator",
      style: style,
      className: merge(className, prefix('divider'))
    });
  }

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

  var item = /*#__PURE__*/React.createElement(Component, _extends({
    "aria-selected": active
  }, rest, {
    tabIndex: tabIndex,
    disabled: Component === SafeAnchor ? disabled : null,
    className: classes,
    onClick: handleClick,
    ref: ref,
    style: style
  }), icon, children, /*#__PURE__*/React.createElement(Ripple, null));
  return hasTooltip ? appendTooltip({
    children: item,
    message: children,
    placement: 'right'
  }) : item;
});
NavItem.defaultProps = defaultProps;
NavItem.displayName = 'NavItem';
NavItem.propTypes = {
  as: PropTypes.elementType,
  active: PropTypes.bool,
  disabled: PropTypes.bool,
  className: PropTypes.string,
  classPrefix: PropTypes.string,
  divider: PropTypes.bool,
  panel: PropTypes.bool,
  onClick: PropTypes.func,
  style: PropTypes.object,
  icon: PropTypes.node,
  onSelect: PropTypes.func,
  children: PropTypes.node,
  eventKey: PropTypes.any,
  tabIndex: PropTypes.number,
  hasTooltip: PropTypes.bool
};
export default NavItem;