define(["loading","connectHelper","globalize","appRouter","emby-input","emby-button","emby-linkbutton","css!./wizard"],function(loading,connectHelper,globalize,appRouter){"use strict";function nextWizardPage(){appRouter.show("wizard/wizardlibrary.html")}function onUpdateUserComplete(result){var msgKey,options;loading.hide(),result.UserLinkResult?(msgKey=result.UserLinkResult.IsPending?"MessagePendingEmbyAccountAdded":"MessageEmbyAccountAdded",options={text:globalize.translate(msgKey),title:globalize.translate("HeaderEmbyAccountAdded")},(void require(["alert"]).then(function(responses){responses[0](options)})).then(nextWizardPage)):nextWizardPage()}function onSubmit(e){return this.querySelector("#txtPassword").value!==this.querySelector("#txtPasswordConfirm").value?require(["alert"],function(alert){alert(globalize.translate("PasswordMatchError"))}):function(form){loading.show();var apiClient=ApiClient;apiClient.ajax({type:"POST",data:{Name:form.querySelector("#txtUsername").value,Password:form.querySelector("#txtPassword").value,ConnectUserName:form.querySelector("#txtConnectUserName").value},url:apiClient.getUrl("Startup/User"),dataType:"json"}).then(onUpdateUserComplete,function(){connectHelper.showLinkUserErrorMessage(form.querySelector("#txtConnectUserName").value)})}(this),e.preventDefault(),!1}function onViewShow(){loading.show();var page=this,apiClient=ApiClient;apiClient.getJSON(apiClient.getUrl("Startup/User")).then(function(user){page.querySelector("#txtUsername").value=user.Name||"",page.querySelector("#txtConnectUserName").value=user.ConnectUserName||"",loading.hide()})}return function(view){view.querySelector(".wizardUserForm").addEventListener("submit",onSubmit),view.addEventListener("viewshow",onViewShow)}});