define(["exports","./../loading/loading.js","./globalize.js"],function(_exports,_loading,_globalize){function ResponseHelper(){}function showAlertAndReject(options,response){function onDone(){return Promise.reject(response)}return function(options){return Emby.importModule("./modules/common/dialogs/alert.js").then(function(alert){return alert(options)})}(options).then(onDone,onDone)}function getErrorObject(response,msg,errorTitle,options){return errorTitle||!1!==(null==options?void 0:options.enableDefaultTitle)&&(errorTitle=_globalize.default.translate("Error")),"string"==typeof response&&msg.push(response),{title:errorTitle,text:msg.join("\n\n")||_globalize.default.translate("DefaultErrorMessage"),html:msg.join("<br/><br/>")||_globalize.default.translate("DefaultErrorMessage"),response:response,centerText:msg.length<2}}function getErrorInfo(response,options){var _response$headers,errorCode=response.errorCode||response,errorTitle=response.errorTitle;switch(errorCode){case"noitems":return Promise.resolve({text:_globalize.default.translate("NoSelectedItemsSupportOperation"),response:response});case"nocommands":return Promise.resolve({text:_globalize.default.translate("NoOperationsForSelectedItems"),response:response});case"RateLimitExceeded":return Promise.resolve({title:errorTitle||_globalize.default.translate("HeaderPlaybackError"),text:_globalize.default.translate("RateLimitExceeded"),response:response});case"NoPlayableItems":case"NoCompatibleStream":case"PlaceHolder":return Promise.resolve({title:errorTitle||_globalize.default.translate("HeaderPlaybackError"),text:_globalize.default.translate("PlaybackError"+errorCode),response:response})}errorTitle||401===response.status&&(errorTitle=_globalize.default.translate("HeaderSignInError"));var msg=[];return response.json&&"application/json"===(null==(_response$headers=response.headers)?void 0:_response$headers.get("Content-Type"))?response.json().then(function(responseInfo){return responseInfo.Message&&msg.push(responseInfo.Message),responseInfo.Title&&(errorTitle=responseInfo.Title),getErrorObject(response,msg,errorTitle,options)}):response.text?response.text().then(function(responseText){return responseText&&msg.push(responseText),getErrorObject(response,msg,errorTitle,options)}):Promise.resolve(getErrorObject(response,msg,errorTitle,options))}Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0,ResponseHelper.prototype.handleConfigurationSavedResponse=function(response){var options;return _loading.default.hide(),options=_globalize.default.translate("SettingsSaved"),Emby.importModule("./modules/toast/toast.js").then(function(toast){toast(options)}),Promise.resolve(response)},ResponseHelper.prototype.getErrorInfo=getErrorInfo,ResponseHelper.prototype.handleErrorResponse=function(response){return _loading.default.hide(),console.error(response||"Error",new Error),getErrorInfo(response).then(function(errorInfo){return showAlertAndReject(errorInfo)})};_exports.default=new ResponseHelper});