define(["exports","./../modules/viewmanager/baseview.js","./../modules/loading/loading.js","./../modules/emby-elements/emby-input/emby-input.js","./../modules/emby-elements/emby-button/emby-button.js","./../modules/emby-elements/emby-scroller/emby-scroller.js","./../modules/emby-apiclient/connectionmanager.js","./../modules/approuter.js"],function(_exports,_baseview,_loading,_embyInput,_embyButton,_embyScroller,_connectionmanager,_approuter){function trimEnd(string,charToRemove){for(;string.charAt(string.length-1)===charToRemove;)string=string.substring(0,string.length-1);return string}function onPortChange(e){var currentPort=(this.value||"").trim();"443"!==currentPort&&"8920"!==currentPort||((currentPort=this.closest("form").querySelector(".txtServerHost")).value=currentPort.value.replace(new RegExp("http:","gi"),"https:"))}function onHostChange(e){var currentHost=(this.value||"").trim().toLowerCase(),txtServerPort=this.closest("form").querySelector(".txtServerPort"),currentPort=txtServerPort.value.trim();currentHost.startsWith("http:")&&["8920","443"].includes(currentPort)?txtServerPort.value="8096":currentHost.startsWith("https:")&&["8096"].includes(currentPort)&&(txtServerPort.value="8920")}function View(view,params){_baseview.default.apply(this,arguments),view.querySelector("form").addEventListener("submit",function(e){e.preventDefault();e=function(address,port){if(port){address=trimEnd(address,"/");try{var url=new URL(address);if(url.port)return address;url.port=port;var urlString=url.toString();if("string"==typeof urlString&&urlString&&!urlString.toLowerCase().includes("object url"))return trimEnd(urlString,"/")}catch(err){console.log("error parsing url: "+err)}address+=":"+port}return address}(this.querySelector(".txtServerHost").value,this.querySelector(".txtServerPort").value);return _loading.default.show(),_connectionmanager.default.connectToAddress(e,{}).then(function(result){_loading.default.hide(),_approuter.default.handleConnectionResult(result)}),!1}),view.querySelector(".txtServerPort").addEventListener("change",onPortChange),view.querySelector(".txtServerHost").addEventListener("change",onHostChange),view.querySelector(".buttonCancel").addEventListener("click",function(e){_approuter.default.back()})}Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0,require(["material-icons"]),Object.assign(View.prototype,_baseview.default.prototype),View.prototype.onResume=function(options){_baseview.default.prototype.onResume.apply(this,arguments);var view=this.view;view.querySelector(".txtServerHost").value="",view.querySelector(".txtServerPort").value="8096"};_exports.default=View});