import{NavbarItemModel,NavbarModel}from"./navbar-model";import{UriUtil}from"../../../../../api/dist/ontotext-workbench-api";import{LoggerProvider}from"../../services/logger-provider";const logger=LoggerProvider.logger;export class NavbarService{static map(e,r,t,o){const i=new NavbarModel;return NavbarService.setTopLevelMenuItems(e,i,r),NavbarService.setSubmenuItems(e,i,r),t&&NavbarService.addRepositoryIdToHrefAttributes(i,t,o),i.sorted()}static addRepositoryIdToHrefAttributes(e,r,t){e.items.forEach(e=>{e.children&&e.children.length>0?e.children.filter(e=>!e.documentationHref).forEach(e=>{e.href=`${e.href}?${t}=${r}`}):e.href=`${e.href}?${t}=${r}`})}static setTopLevelMenuItems(e,r,t){e.forEach(e=>{e.items.filter(e=>!e.parent&&e.shouldShow).forEach(e=>{r.hasParent(e.label)?logger.warn("Doubled parent definition: ",e):r.addItem(this.toMenuItemModel(e,void 0,t,e.children))})})}static setSubmenuItems(e,r,t){e.forEach(e=>{e.items.filter(e=>e.parent&&e.shouldShow).forEach(e=>{const o=r.getTopLevelItem(e.parent);null==o||o.addChildren(this.toMenuItemModel(e,o,t,e.children))})})}static toMenuItemModel(e,r,t,o=[]){let i;e.documentationHref&&(i=UriUtil.resolveDocumentationUrl(null==t?void 0:t.shortVersion,e.documentationHref));const a=new NavbarItemModel({label:e.label,labelKey:e.labelKey,href:i||e.href,documentationHref:e.documentationHref,hrefFun:e.hrefFun,order:e.order,role:e.role,editions:e.editions,icon:e.icon,guideSelector:e.guideSelector,hasParent:!!r,parentModel:r,parent:e.parent,selected:!1,shouldShow:e.shouldShow,testSelector:e.testSelector}),l=o.map(e=>this.toMenuItemModel(e,a,t,e.children));return a.addChildren(...l),a}}