"use strict";

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