var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.convertSidebarItemsToPathsArray=convertSidebarItemsToPathsArray;exports.findPageById=findPageById;exports.getGithubLink=getGithubLink;exports.getPrevAndNextLinks=getPrevAndNextLinks;exports.showToc=showToc;var _toConsumableArray2=_interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));function convertSidebarItemsToPathsArray(sidebarItems){var pages=[];if(sidebarItems&&(sidebarItems==null?void 0:sidebarItems.length)>0){for(var i=0;i<sidebarItems.length;i++){var _page$pages;var page=sidebarItems[i];if(page&&page.id){var x={};x[page==null?void 0:page.title]=page.id;pages.push(x);}if((page==null?void 0:(_page$pages=page.pages)==null?void 0:_page$pages.length)>0){pages.push.apply(pages,(0,_toConsumableArray2.default)(convertSidebarItemsToPathsArray(page.pages)));}}}return pages;}function getPrevAndNextLinks(pages,currentRoute){var currentIndex=pages.findIndex(function(page){return Object.values(page)[0]===currentRoute;});var prevIndex=currentIndex-1;var nextIndex=currentIndex+1;var prevLink=prevIndex>=0?Object.values(pages[prevIndex])[0]:null;var prevText=prevIndex>=0?Object.keys(pages[prevIndex])[0]:null;var nextLink=nextIndex<pages.length?Object.values(pages[nextIndex])[0]:null;var nextText=nextIndex<pages.length?Object.keys(pages[nextIndex])[0]:null;return{prev:prevText,prevLink:prevLink,next:nextText,nextLink:nextLink};}function getGithubLink(sidebarItems,pathName){for(var i=0;i<sidebarItems.length;i++){var currentItem=sidebarItems[i];if(currentItem.pages){var githubLink=getGithubLink(currentItem.pages,pathName);if(githubLink){return githubLink;}}if(currentItem.id===pathName){return currentItem.githubPath;}}return null;}function showToc(sidebarItems,pathName){var _page$metaData;var page=findPageById(pathName,sidebarItems);if((page==null?void 0:(_page$metaData=page.metaData)==null?void 0:_page$metaData.toc)==false){return false;}else{return true;}}function findPageById(id,pages){for(var page of pages){if(page.id===id){return page;}if(page.pages){var result=findPageById(id,page.pages);if(result){return result;}}}return null;}
//# sourceMappingURL=helperFunction.js.map