export class NavbarModel{constructor(e=[]){this._items=e}hasParent(e){return this._items.some(t=>e===t.label)}getModel(){const e=t=>{const s=t.children.map(e);return new NavbarItemModel(Object.assign(Object.assign({},t),{children:s}))};return this._items.map(e)}addItem(e){this._items.push(e)}getSelectedRootItem(){return this._items.find(e=>e.selected)}isParentOpened(e){var t;return!!(null===(t=this.getParentItem(e))||void 0===t?void 0:t.open)}getTopLevelItem(e){return this._items.find(t=>t.label===e)}getParentItem(e){return this._items.find(t=>t.label===e.parent)}deselectAll(){this.walk(e=>{e.selected=!1})}closeAll(){this.walk(e=>{this.setOpen(e,!1)})}deselectItem(e){e.selected=!1}selectItem(e){e.label?e.selected=!0:this.selectItem(e.parentModel)}hasSelectedSubmenu(e){return!!e.children&&e.children.some(e=>this.hasSelection(e))}hasSelection(e){return!!e.selected||!!e.children&&e.children.some(e=>this.hasSelection(e))}closeOpened(){const e=this._items.find(e=>e.open);e&&(this.hasSelectedSubmenu(e)&&this.selectItem(e),this.setOpen(e,!1))}open(e){this.walk(e=>{this.setOpen(e,!1)}),this.openItemAndParent(e)}openItemAndParent(e){e.parentModel&&this.openItemAndParent(e.parentModel),this.setOpen(e,!0)}closeOtherParents(e){const t=e.parent;this.walk(e=>{e.label!==t&&this.setOpen(e,!1)})}setOpen(e,t){e.open=t}highlightSelected(){const e=this.getSelectedItem();(null==e?void 0:e.hasParent)&&this.selectItem(this.getParentItem(e))}unhighlightSelected(){const e=this.getSelectedRootItem();e&&e.children.length&&e.open&&this.deselectItem(e)}getSelectedItem(){let e=null;const t=s=>{if(s.selected)return e=s,!0;if(s.children)for(const e of s.children)if(t(e))return!0;return!1};return this._items.some(t),e}expandSelected(){const e=this.getSelectedItem();e&&(e.hasParent?this.open(this.getParentItem(e)):this.open(e))}initSelected(e){this.walk(t=>{var s;let r=e;(null===(s=t.href)||void 0===s?void 0:s.includes("*"))&&(r=this.getWildcardPath(e,t.href));const i=t.href.search(/[?]/);r===(-1===i?t.href:t.href.substring(0,i))&&(t.hasParent&&this.open(t),this.selectItem(t))})}getWildcardPath(e,t){const s=e.split("/"),r=t.split("/");if(s.length!==r.length)return e;const i=[];for(let t=0;t<r.length;t++)if("*"===r[t])i.push("*");else{if(r[t]!==s[t])return e;i.push(r[t])}return i.join("/")}sorted(){return this._items.filter(e=>e.children).forEach(e=>{e.children.sort(NavbarModel.compare)}),this._items.sort(NavbarModel.compare),this}static compare(e,t){return e.order-t.order}walk(e){this.walkRecursively(this.items,e)}walkRecursively(e,t){e.forEach(e=>{var s;t(e),(null===(s=e.children)||void 0===s?void 0:s.length)&&this.walkRecursively(e.children,t)})}get items(){return this._items}}export class NavbarItemModel{constructor(e){var t;this._selected=!1,this._open=!1,this._order=e.order,this._label=e.label,this._labelKey=e.labelKey,this._href=e.href,this._children=[...null!==(t=e.children)&&void 0!==t?t:[]],this._hasParent=e.hasParent,this._parent=e.parent,this._selected=e.selected,this._open=e.open,this._documentationHref=e.documentationHref,this._hrefFun=e.hrefFun,this._editions=e.editions,this._icon=e.icon,this._role=e.role,this._guideSelector=e.guideSelector,this._testSelector=e.testSelector,this._shouldShow=e.shouldShow,this._parentModel=e.parentModel}addChild(e){this.children.push(e),e.setParent(this)}addChildren(...e){e.forEach(e=>{this.addChild(e)})}hasSubmenus(){return"#"===this._href}get parent(){return this._parent}set parent(e){this._parent=e}get order(){return this._order}set order(e){this._order=e}get label(){return this._label}set label(e){this._label=e}get labelKey(){return this._labelKey}set labelKey(e){this._labelKey=e}get documentationHref(){return this._documentationHref}set documentationHref(e){this._documentationHref=e}get href(){return this._href}set href(e){this._href=e}get children(){return this._children}set children(e){this._children=e}get hasParent(){return this._hasParent}set hasParent(e){this._hasParent=e}get selected(){return this._selected}set selected(e){this._selected=e}get open(){return this._open}set open(e){this._open=e}get hrefFun(){return this._hrefFun}set hrefFun(e){this._hrefFun=e}get editions(){return this._editions}set editions(e){this._editions=e}get icon(){return this._icon}set icon(e){this._icon=e}get role(){return this._role}set role(e){this._role=e}get guideSelector(){return this._guideSelector}set guideSelector(e){this._guideSelector=e}get testSelector(){return this._testSelector}set testSelector(e){this._testSelector=e}get parentModel(){return this._parentModel}set parentModel(e){this._parentModel=e}get shouldShow(){return this._shouldShow}set shouldShow(e){this._shouldShow=e}setParent(e){this.parentModel=e,this.hasParent=!!e}}