import dom from"./../modules/dom.js";import globalize from"./../modules/common/globalize.js";import loading from"./../modules/loading/loading.js";import formHelper from"./../modules/common/responsehelper.js";import pluginManager from"./../modules/common/pluginmanager.js";function showToast(options){return Emby.importModule("./modules/toast/toast.js").then(function(toast){return toast(options)})}function showAlert(options){return Emby.importModule("./modules/common/dialogs/alert.js").then(function(alert){return alert(options)})}function showConfirm(options){return Emby.importModule("./modules/common/dialogs/confirm.js").then(function(confirm){return confirm(options)})}function getWindowLocationSearch(win){let search=(win||globalThis).location.search;return search||-1!==(win=globalThis.location.href.indexOf("?"))&&(search=globalThis.location.href.substring(win)),search||""}globalThis.getWindowLocationSearch=getWindowLocationSearch,globalThis.getParameterByName=function(name,url){name=name.replace(/[\[]/,"\\[").replace(/[\]]/,"\\]");name=new RegExp("[\\?&]"+name+"=([^&#]*)","i").exec(url||getWindowLocationSearch());return null==name?"":decodeURIComponent(name[1].replace(/\+/g," "))};let Dashboard=globalThis.Dashboard||(globalThis.Dashboard={});Dashboard.confirm=function(message,title,callback){showConfirm(message,title).then(function(){callback(!0)},function(){callback(!1)})},Dashboard.showLoadingMsg=function(){loading.show()},Dashboard.hideLoadingMsg=function(){loading.hide()},Dashboard.getCurrentUser=function(){return ApiClient.getCurrentUser()},Dashboard.getCurrentUserId=function(){return ApiClient.getCurrentUserId()},Dashboard.navigate=function(url,preserveQueryString){var queryString;if(url)return queryString=getWindowLocationSearch(),preserveQueryString&&queryString&&(url+=queryString),Emby.importModule("./modules/approuter.js").then(function(appRouter){return appRouter.show(url)});throw new Error("url cannot be null or empty")},Dashboard.processPluginConfigurationUpdateResult=function(){loading.hide(),formHelper.handleConfigurationSavedResponse()},Dashboard.getConfigurationPageUrl=function(name){return pluginManager.getConfigurationPageUrl(name)},Dashboard.getConfigurationResourceUrl=function(name){return pluginManager.getConfigurationResourceUrl(name)},Dashboard.alert=function(options){"string"==typeof options?showToast({text:options}):showAlert({title:options.title||globalize.translate("HeaderAlert"),text:options.message}).then(options.callback||function(){})},Dashboard.processServerConfigurationUpdateResult=function(response){return formHelper.handleConfigurationSavedResponse(response)},Dashboard.processErrorResponse=function(response){return formHelper.handleErrorResponse(response)},globalThis.pageClassOn=function(eventName,className,fn){document.addEventListener(eventName,function(e){var target=e.target;target.classList.contains(className)&&fn.call(target,e)})},globalThis.pageIdOn=function(eventName,id,fn){document.addEventListener(eventName,function(e){var target=e.target;target.id===id&&fn.call(target,e)})},dom.parentWithClass=function(elem,classNames){return Array.isArray(classNames)?elem.closest("."+classNames.join(",.")):elem.closest("."+classNames)};