define(["exports","./../layoutmanager.js","./../focusmanager.js","./../common/pluginmanager.js","./../common/usersettings/usersettings.js","./../emby-apiclient/events.js","./../common/appsettings.js","./../emby-elements/emby-scroller/emby-scroller.js"],function(_exports,_layoutmanager,_focusmanager,_pluginmanager,_usersettings,_events,_appsettings,_embyScroller){Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0;var mainAnimatedPages,splashRemoved,ViewClasses=[],CurrentViewStack=[];function removeViewInfoFromCurrentViews(viewInfo){var arr;viewInfo=viewInfo,-1<(viewInfo=(arr=CurrentViewStack).indexOf(viewInfo))&&arr.splice(viewInfo,1)}function disableRestoreOnCurrentViews(){for(var views=CurrentViewStack,i=0,length=views.length;i--\x3e","<\/script>")),(hasScript=document.createElement("div")).innerHTML=html,hasScript.querySelector('.view,div[data-role="page"]')}(viewHtml,_options$params);options.view=isPluginpage}function getViewHideEventInfo(previousViewInfo,newViewInfo){previousViewInfo=Object.assign({},previousViewInfo);return previousViewInfo.newViewInfo=newViewInfo,{detail:previousViewInfo,bubbles:!0,cancelable:!1}}function dispatchViewBeforeHide(instance,view,eventInfo,dispatchLegacyPageEvent){var _view$controller;null!=(_view$controller=view.controller)&&_view$controller.onPause({event:eventInfo,newViewInfo:null==(_view$controller=eventInfo.detail)?void 0:_view$controller.newViewInfo}),instance.onBeforeHide&&instance.onBeforeHide(eventInfo),dispatchViewEvent(view,eventInfo,"viewbeforehide",dispatchLegacyPageEvent)}function onBeforeChange(instance,previousViewInfo,newViewInfo,isRestored,isBack){previousViewInfo&&dispatchViewBeforeHide(instance,previousViewInfo.view,getViewHideEventInfo(previousViewInfo,newViewInfo),!0);instance=newViewInfo.view,isRestored=getViewEventDetail(newViewInfo,isRestored,isBack,previousViewInfo),isBack=isRestored.detail.navMenuId;isBack||"search"===(null==(previousViewInfo=isRestored.detail.params)?void 0:previousViewInfo.type)&&(isBack="search"),isBack=isBack||(isBack=window.location.href.toString()).substring(isBack.indexOf("#!")+2),isRestored.detail.navMenuId=isBack,newViewInfo.controllerFactory&&!instance.controller&&(instance.controller=new newViewInfo.controllerFactory(instance,isRestored.detail.params)),newViewInfo.controller&&instance.controller&&(previousViewInfo=function(urlOrPath){try{var pathname=new URL(urlOrPath).pathname;if(pathname)return pathname}catch(e){}return urlOrPath}(newViewInfo.controller),instance.controller.name=previousViewInfo.replaceAll(".js","").replaceAll(".","").replaceAll("/","-"),instance.classList.add("view-"+instance.controller.name)),dispatchViewEvent(instance,isRestored,"viewbeforeshow",!0)}function onViewChange(previousViewInfo,newViewInfo,isRestore,isBack){previousViewInfo&&dispatchViewEvent(previousViewInfo.view,getViewHideEventInfo(previousViewInfo,newViewInfo),"viewhide",!0),isRestore&&removeViewInfoFromCurrentViews(newViewInfo),CurrentViewStack.push(newViewInfo);var _newView$controller,newView=newViewInfo.view;return((null==(_newView$controller=newView.controller)?void 0:_newView$controller.transitionPromise)||Promise.resolve()).then(function(){return function(viewInfo,isRestore,isBack,previousViewInfo){(function(){var splash;!splashRemoved&&(splashRemoved=!0,splash=document.querySelector(".app-splash-container")||document.querySelector(".app-splash"))&&splash.remove()})();var _viewInfo$params,newView=viewInfo.view,eventDetail=getViewEventDetail(viewInfo,isRestore,isBack,previousViewInfo);"true"!==(null==previousViewInfo?void 0:previousViewInfo.params.asDialog)||"true"===(null==(_viewInfo$params=viewInfo.params)?void 0:_viewInfo$params.asDialog)&&!isBack||removeAndDestroy(previousViewInfo);viewInfo.abortController.signal.aborted?console.log("aborting onNewViewDisplayed due to leaving view"):(isRestore?(_viewInfo$params=viewInfo.activeElement)&&document.body.contains(_viewInfo$params)&&_focusmanager.default.isCurrentlyFocusable(_viewInfo$params)?_focusmanager.default.focus(_viewInfo$params):autoFocusView(newView,{skipIfNotEnabled:!0}):!1!==viewInfo.autoFocus&&autoFocusView(newView,{skipIfNotEnabled:!0}),(isBack=function(e){return{refresh:!e.detail.isRestored,previousViewInfo:e.detail.previousViewInfo,signal:null==(e=e.detail.abortController)?void 0:e.signal}}(eventDetail)).autoFocus=!eventDetail.detail.isRestored,null!=(previousViewInfo=newView.controller)&&previousViewInfo.onResume(isBack),newView.dispatchEvent(new CustomEvent("viewshow",eventDetail)),newView.classList.contains("needsPageEvents")&&newView.dispatchEvent(new CustomEvent("pageshow",eventDetail)))}(newViewInfo,isRestore,isBack,previousViewInfo),newView})}function autoFocusView(view,options){var controller=view.controller;return controller&&controller.autoFocus?controller.autoFocus(options):_focusmanager.default.autoFocus(view,options)}function dispatchViewEvent(view,eventInfo,eventName,dispatchLegacyPageEvent){view.dispatchEvent(new CustomEvent(eventName,eventInfo));if(dispatchLegacyPageEvent&&view.classList.contains("needsPageEvents"))try{view.dispatchEvent(new CustomEvent(eventName.replace("view","page"),eventInfo))}catch(err){console.log("error dispatching page event: "+err)}}function getViewEventDetail(viewInfo,isRestore,isBack,previousViewInfo){var view=viewInfo.view;return viewInfo.isRestored=isRestore,viewInfo.isBack=isBack,viewInfo.previousViewInfo=previousViewInfo,null==viewInfo.title&&(viewInfo.title=view.getAttribute("data-title")||null),viewInfo.helpUrl||(viewInfo.helpUrl=view.getAttribute("data-helpurl")||null),{detail:viewInfo,bubbles:!0,cancelable:!1}}function removeAndDestroy(viewInfoToRemove,newViewToReplaceWith){removeViewInfoFromCurrentViews(viewInfoToRemove);var viewInfo,_viewInfo$abortContro,viewToRemove=viewInfoToRemove.view;((viewInfo=viewInfoToRemove).activeElement=null)!=(_viewInfo$abortContro=viewInfo.abortController)&&_viewInfo$abortContro.abort(),_viewInfo$abortContro=viewInfo.view,null!=(viewInfo=_viewInfo$abortContro.controller)&&viewInfo.destroy&&viewInfo.destroy(),_viewInfo$abortContro.controller=null,"true"!==viewInfoToRemove.params.asDialog&&(newViewToReplaceWith?mainAnimatedPages.replaceChild(newViewToReplaceWith,viewToRemove):viewToRemove.remove())}function ViewManager(){}_events.default.on(_layoutmanager.default,"modechange",disableRestoreOnCurrentViews),_events.default.on(_usersettings.default,"change",function(e,name){switch(name){case"tvhome":case"enableHomescreenFocusPreviews":disableRestoreOnCurrentViews()}}),_events.default.on(_appsettings.default,"change",function(e,name){switch(name){case"name":case"datetimelocale":case"language":disableRestoreOnCurrentViews()}}),ViewManager.prototype.loadView=function(options,signal){var instance=this,previousViewInfo=this.currentViewInfo(),isPluginpage=(previousViewInfo&&(previousViewInfo.activeElement=document.activeElement),options.isPluginPage),view=(normalizeNewView(options,isPluginpage),options.view),dependencies=view.getAttribute("data-require"),dependencyPromises=[];return(dependencies=dependencies?dependencies.split(","):[]).length&&dependencyPromises.push(require(dependencies)),isPluginpage&&(dependencyPromises.push(Emby.importModule("./legacy/dashboard.js")),dependencyPromises.push(require(["css!legacy/dashboard.css"]))),Promise.all(dependencyPromises).then(function(){var viewClassList=view.classList;return viewClassList.add("page"),isPluginpage&&(viewClassList.add("needsPageEvents"),function(view){var scrollSlider,content,scroller=view.querySelector('[is="emby-scroller"]');scroller||view.closest('[is="emby-scroller"]')||((content=view.querySelector(':scope > [data-role="content"], :scope > .content-primary'))&&(scroller=view,scrollSlider=content),scroller&&scrollSlider||(scrollSlider=null==(scroller=view.querySelector('[data-role="content"]'))?void 0:scroller.querySelector(":scope > .content-primary")),scroller&&scrollSlider?(scroller.classList.add("scrollFrameY"),scroller.setAttribute("data-horizontal","false"),scroller.setAttribute("data-forcescrollbar","true"),scroller.setAttribute("data-bindheader","true"),scroller.setAttribute("is","emby-scroller"),scroller.is="emby-scroller",scrollSlider.classList.add("scrollSlider","padded-top-page","padded-bottom-page","padded-left","padded-right","padded-left-page"),_embyScroller.default.upgradeElement(scroller)):null!=(content=view.querySelector(".content-primary"))&&content.classList.add("padded-top-page","padded-bottom-page","padded-left","padded-right","padded-left-page"))}(view)),viewClassList.add.apply(viewClassList,ViewClasses),mainAnimatedPages=mainAnimatedPages||document.querySelector(".mainAnimatedPages"),"true"!==(null==(viewClassList=options.params)?void 0:viewClassList.asDialog)&&((viewClassList=function(ignoreViewInfo){for(var candidates=[],views=CurrentViewStack,i=0,length=views.length;i