"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.SubNavigationItem = void 0;
var _react = _interopRequireDefault(require("react"));
var _classnames = _interopRequireDefault(require("classnames"));
var _subNavigationItemContent = require("./sub-navigation-item-content");
var _button = require("../button");
var _tooltip = require("../tooltip");
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const SubNavigationItem = ({
  item,
  selectedTabKey,
  LinkComponent,
  hasLink,
  onSelect = () => {}
}) => {
  const isShown = item.isShown === undefined ? true : item.isShown;
  const className = (0, _classnames.default)('sub-nav-item header-sub-navigation item-button', item.customClassName);
  if (!isShown) {
    return null;
  }
  const ariaAttr = {
    'aria-selected': item.key === selectedTabKey,
    role: 'tab'
  };
  if (item.route || item.indexRoute) {
    return (
      /*#__PURE__*/
      // eslint-disable-next-line @typescript-eslint/ban-ts-comment
      // @ts-ignore
      (0, _jsxRuntime.jsx)(LinkComponent, {
        item: item,
        className: className,
        onSelect: onSelect
      })
    );
  }
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_button.Button, {
    type: _button.BUTTON_TYPES.BUTTON,
    accentType: _button.ACCENT_TYPES.COMMAND,
    testId: item.testId,
    tourId: item.tourId,
    className: (0, _classnames.default)(className, {
      active: item.key === selectedTabKey
    }),
    onClick: () => onSelect(item),
    isDisabled: item.disabled,
    tooltipText: item.toolTip,
    tooltipPlacement: _tooltip.TOOLTIP_PLACEMENT_TYPES.BOTTOM,
    tooltipDocsLink: item.docsLink,
    ...(!hasLink ? ariaAttr : {}),
    children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_subNavigationItemContent.SubNavigationItemContent, {
      label: item.label,
      leftElement: item.leftElement,
      rightElement: item.rightElement
    })
  });
};
exports.SubNavigationItem = SubNavigationItem;