"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = exports.VerticalNav = void 0;
var _compat = _interopRequireDefault(require("preact/compat"));
var _VerticalNavItem = _interopRequireDefault(require("./VerticalNavItem"));
var _classnames = _interopRequireDefault(require("classnames"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _extends() { _extends = Object.assign ? Object.assign.bind() : 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; }; return _extends.apply(this, arguments); }
/**
 * For information about how and when to use this component,
 * [refer to its full documentation page](https://design.cms.gov/components/vertical-navigation/).
 */
var VerticalNav = function VerticalNav(props) {
  var classes = (0, _classnames.default)({
    'ds-c-vertical-nav': !props.nested,
    'ds-c-vertical-nav__subnav': props.nested,
    'ds-c-vertical-nav--collapsed': props.collapsed
  }, props.className);
  var navProps = props.ariaNavLabel ? {
    'aria-label': props.ariaNavLabel
  } : {};
  var navList = /*#__PURE__*/_compat.default.createElement("ul", {
    role: "list",
    className: classes,
    id: props.id
  }, props.items.map(function (item) {
    var onClick = item.onClick || props.onLinkClick;
    if (!onClick) {
      onClick = undefined;
    }
    var selected = item.selected || props.selectedId && props.selectedId === item.id;
    return /*#__PURE__*/_compat.default.createElement(_VerticalNavItem.default, _extends({}, item, {
      component: props.component || item.component,
      _selectedId: props.selectedId,
      key: item.id + item.url + item.label,
      onClick: onClick,
      selected: selected
    }));
  }));
  return props.nested ? navList : /*#__PURE__*/_compat.default.createElement("nav", navProps, navList);
};
exports.VerticalNav = VerticalNav;
VerticalNav.defaultProps = {
  collapsed: false
};
var _default = VerticalNav;
exports.default = _default;