define(["exports","./../common/globalize.js","./../loading/loading.js","./../common/dialogs/alert.js","./../common/servicelocator.js"],function(_exports,_globalize,_loading,_alert,_servicelocator){function resolvePromise(){return Promise.resolve()}function rejectPromise(){return Promise.reject()}function showConnectServerUnreachableErrorMessage(){var text=_globalize.default.translate("ErrorConnectServerUnreachable","https://connect.emby.media");return(0,_alert.default)({text:text})}Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0;_exports.default={updateUserLink:function(apiClient,user,newConnectUsername){var currentConnectUsername=user.ConnectUserName||"";return currentConnectUsername&&!newConnectUsername?apiClient.removeEmbyConnectLink(user.Id).then(function(){return _loading.default.hide(),(0,_alert.default)({text:_globalize.default.translate("MessageEmbyAccontRemoved"),title:_globalize.default.translate("HeaderEmbyAccountRemoved")}).catch(resolvePromise)},function(response){return _loading.default.hide(),(502===(response?response.status:0)?showConnectServerUnreachableErrorMessage():(0,_alert.default)({text:_globalize.default.translate("ErrorRemovingEmbyConnectAccount")})).then(rejectPromise)}):currentConnectUsername!==newConnectUsername?(currentConnectUsername=apiClient.getUrl("Users/"+user.Id+"/Connect/Link"),apiClient.ajax({type:"POST",url:currentConnectUsername,data:{ConnectUsername:newConnectUsername},dataType:"json"}).then(function(result){result=result.IsPending?"MessagePendingEmbyAccountAdded":"MessageEmbyAccountAdded";return _loading.default.hide(),(0,_alert.default)({text:_globalize.default.translate(result),title:_globalize.default.translate("HeaderEmbyAccountAdded")}).catch(resolvePromise)},function(response){_loading.default.hide();response=response?response.status:0;return(502===response?showConnectServerUnreachableErrorMessage():function(username,statusCode){var html,text;return 502===statusCode?showConnectServerUnreachableErrorMessage():(409===statusCode?text=_globalize.default.translate("EmbyConnectUserAlreadyLinked"):username?(_servicelocator.appHost.supports("externallinks")&&(html=_globalize.default.translate("ErrorAddingEmbyConnectAccount1",'<a is="emby-linkbutton" class="button-link" href="https://emby.media/connect" target="_blank">https://emby.media/connect</a>'),html+="<br/><br/>"+_globalize.default.translate("ErrorAddingEmbyConnectAccount2","support@emby.media")),text=_globalize.default.translate("ErrorAddingEmbyConnectAccount1","https://emby.media/connect"),text+="\n\n"+_globalize.default.translate("ErrorAddingEmbyConnectAccount2","support@emby.media")):html=text=_globalize.default.translate("DefaultErrorMessage"),(0,_alert.default)({text:text,html:html}))}(".",response)).then(rejectPromise)})):Promise.reject()}}});