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); }
import React from "preact/compat";
import VerticalNavItem from "./VerticalNavItem";
import classNames from 'classnames';
/**
 * For information about how and when to use this component,
 * [refer to its full documentation page](https://design.cms.gov/components/vertical-navigation/).
 */
export var VerticalNav = function VerticalNav(props) {
  var classes = classNames({
    '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__*/React.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__*/React.createElement(VerticalNavItem, _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__*/React.createElement("nav", navProps, navList);
};
VerticalNav.defaultProps = {
  collapsed: false
};
export default VerticalNav;