"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.SubNavigation = void 0;
var _react = _interopRequireWildcard(require("react"));
var _classnames = _interopRequireDefault(require("classnames"));
var _types = require("./types");
var _subNavigationItem = require("./sub-navigation-item");
var _subNavigationItemLink = require("./sub-navigation-item-link");
var _adaptiveList = require("../adaptive-list");
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
/** Sub navigation bars display items with label text. When label tapped, the user is taken to the navigation destination
 * [CAPITALIZATION] Use title case
 * @midnight-gray-supported
 * @alpine-light-supported
 */
const SubNavigation = ({
  navigationItems,
  activeTab,
  testId,
  onSelect = () => {},
  customClassName = '',
  LinkComponent = _subNavigationItemLink.SubNavigationItemLink,
  accentType = _types.SUB_NAVIGATION_ACCENT_TYPES.INLINE,
  size = _types.SUB_NAVIGATION_ACCENT_SIZES.SMALL,
  isAdaptive = false,
  isUnderlined = false
}) => {
  const options = (0, _react.useMemo)(() => {
    return navigationItems.map(navigationItem => ({
      title: navigationItem.label,
      ...navigationItem
    })).filter(({
      isShown
    }) => isShown !== false);
  }, [navigationItems]);
  const hasLink = navigationItems.some(item => item.route || item.indexRoute);
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
    className: (0, _classnames.default)('sub-nav-group', accentType, size, customClassName, {
      underlined: isUnderlined
    }),
    "test-id": testId,
    role: !isAdaptive && !hasLink ? 'tablist' : undefined // AdaptiveList applies it's own tablist role
    ,
    children: isAdaptive ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_adaptiveList.AdaptiveList, {
      selected: activeTab,
      onSelect: option => onSelect(option),
      options: options,
      isSubNavItem: !hasLink,
      Component: ({
        option
      }) => /*#__PURE__*/(0, _jsxRuntime.jsx)(_subNavigationItem.SubNavigationItem, {
        item: option,
        selectedTabKey: activeTab,
        onSelect: onSelect,
        LinkComponent: LinkComponent,
        hasLink: hasLink
      })
    }) : navigationItems.map(item => /*#__PURE__*/(0, _jsxRuntime.jsx)(_subNavigationItem.SubNavigationItem, {
      hasLink: hasLink,
      item: item,
      selectedTabKey: activeTab,
      onSelect: onSelect,
      LinkComponent: LinkComponent
    }, item.key))
  });
};
exports.SubNavigation = SubNavigation;