define(["exports","./../dialoghelper/dialoghelper.js","./../layoutmanager.js","./../common/globalize.js","./../loading/loading.js","./../common/servicelocator.js","./../emby-elements/emby-button/emby-button.js","./../emby-elements/emby-button/paper-icon-button-light.js","./../emby-elements/emby-scroller/emby-scroller.js"],function(_exports,_dialoghelper,_layoutmanager,_globalize,_loading,_servicelocator,_embyButton,_paperIconButtonLight,_embyScroller){Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0,require(["material-icons","formDialogStyle","flexStyles"]);var MaxWaitMinutes=5;function retryReload(instance){setTimeout(function(){Date.now()<instance.waitStartTime+60*MaxWaitMinutes*1e3&&!function(instance){var apiClient=instance.apiClient;apiClient&&apiClient.getJSON(apiClient.getUrl("System/Info")).then(function(info){info.IsShuttingDown?retryReload(instance):(instance.restarted=!0,_dialoghelper.default.close(instance.dlg))},function(){retryReload(instance)})}(instance)},500)}function showDialog(instance,options,template){for(var dialogOptions={removeOnClose:!0,scrollY:!1},enableTvLayout=_layoutmanager.default.tv,dlg=(enableTvLayout&&(dialogOptions.size="fullscreen"),_dialoghelper.default.createDialog(dialogOptions)),configuredButtons=[],dialogOptions=(dlg.classList.add("formDialog"),dlg.innerHTML=_globalize.default.translateHtml(template,"sharedcomponents"),dlg.classList.add("align-items-center"),dlg.classList.add("justify-items-center"),dlg.querySelector(".formDialogContent")),html=(dialogOptions.style["flex-grow"]="initial",enableTvLayout?(dialogOptions.style["max-width"]="50%",dialogOptions.style["max-height"]="60%"):dlg.style.maxWidth="25em",dlg.querySelector(".formDialogHeaderTitle").innerHTML=_globalize.default.translate("HeaderRestartingEmbyServer"),dlg.querySelector(".dialogContentInner").innerHTML=_globalize.default.translate("RestartPleaseWaitMessage"),""),i=0,length=configuredButtons.length;i<length;i++){var item=configuredButtons[i],buttonClass="btnOption raised formDialogFooterItem formDialogFooterItem-autosize";item.type&&(buttonClass+=" button-"+item.type),html+='<button is="emby-button" type="button" class="'+buttonClass+'" data-id="'+item.id+'">'+item.name+"</button>"}function onButtonClick(){_dialoghelper.default.close(dlg)}dlg.querySelector(".formDialogFooter").innerHTML=html;var buttons=dlg.querySelectorAll(".btnOption");for(i=0,length=buttons.length;i<length;i++)buttons[i].addEventListener("click",onButtonClick);template=_dialoghelper.default.open(dlg);return function(instance,apiClient,dlg){instance.apiClient=apiClient,instance.dlg=dlg,apiClient.restartServer().then(function(){instance.waitStartTime=Date.now(),retryReload(instance)})}(instance,options.apiClient,dlg),template.then(function(){instance.destroy(),_loading.default.hide(),instance.restarted&&(_servicelocator.appHost.supports("multiserver")?options.apiClient.ensureWebSocket():window.location.reload(!0))})}function ServerRestartDialog(options){this.options=options}ServerRestartDialog.prototype.show=function(){var instance=this;return _loading.default.show(),new Promise(function(resolve,reject){require(["dialogTemplateHtml"],function(template){showDialog(instance,instance.options,template).then(resolve,reject)})})},ServerRestartDialog.prototype.destroy=function(){this.options=null};_exports.default=ServerRestartDialog});