define(["exports","./../common/globalize.js","./../loading/loading.js","./../common/dialogs/alert.js","./../common/servicelocator.js","./../common/responsehelper.js"],function(_exports,_globalize,_loading,_alert,_servicelocator,_responsehelper){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){return _loading.default.hide(),function(response,username,statusCode){var html;return 502===statusCode?showConnectServerUnreachableErrorMessage():409===statusCode?(0,_alert.default)({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")),statusCode=_globalize.default.translate("ErrorAddingEmbyConnectAccount1","https://emby.media/connect"),statusCode+="\n\n"+_globalize.default.translate("ErrorAddingEmbyConnectAccount2","support@emby.media"),(0,_alert.default)({text:statusCode,html:html})):_responsehelper.default.handleErrorResponse(response)}(response,".",null==response?void 0:response.status).then(rejectPromise)})):Promise.reject()}}});