define(["appSettings","events","browser"],function(appsettings,events,browser){"use strict";functiononSaveTimeout(){varself=this;self.saveTimeout=null,self.currentApiClient.updateDisplayPreferences("usersettings",self.displayPrefs,self.currentUserId,"emby")}functionsaveServerPreferences(instance){instance.saveTimeout&&clearTimeout(instance.saveTimeout),instance.saveTimeout=setTimeout(onSaveTimeout.bind(instance),50)}functionUserSettings(){}functiongetSavedQueryKey(context){return"query-"+context}returnUserSettings.prototype.setUserInfo=function(userId,apiClient){if(this.saveTimeout&&clearTimeout(this.saveTimeout),this.currentUserId=userId,this.currentApiClient=apiClient,!userId)returnthis.displayPrefs=null,Promise.resolve();varself=this;returnapiClient.getDisplayPreferences("usersettings",userId,"emby").then(function(result){result.CustomPrefs=result.CustomPrefs||{},self.displayPrefs=result})},UserSettings.prototype.getData=function(){returnthis.displayPrefs},UserSettings.prototype.importFrom=function(instance){this.displayPrefs=instance.getData()},UserSettings.prototype.set=function(name,value,enableOnServer){varuserId=this.currentUserId;if(!userId)thrownewError("userId cannot be null");varcurrentValue=this.get(name);appsettings.set(name,value,userId),enableOnServer!==!1&&this.displayPrefs&&(this.displayPrefs.CustomPrefs[name]=null==value?value:value.toString(),saveServerPreferences()),currentValue!==value&&events.trigger(this,"change",[name])},UserSettings.prototype.get=function(name,enableOnServer){varuserId=this.currentUserId;returnuserId?enableOnServer!==!1&&this.displayPrefs?this.displayPrefs.CustomPrefs[name]:appsettings.get(name,userId):null},UserSettings.prototype.serverConfig=function(config){varapiClient=this.currentApiClient;returnconfig?apiClient.updateUserConfiguration(this.currentUserId,config):apiClient.getUser(this.currentUserId).then(function(user){returnuser.Configuration})},UserSettings.prototype.enableCinemaMode=function(val){returnnull!=val&&this.set("enableCinemaMode",val.toString(),!1),val=this.get("enableCinemaMode",!1),!val||"false"!==val},UserSettings.prototype.enableThemeSongs=function(val){returnnull!=val&&this.set("enableThemeSongs",val.toString(),!1),val=this.get("enableThemeSongs",!1),"false"!==val},UserSettings.prototype.enableThemeVideos=function(val){returnnull!=val&&this.set("enableThemeVideos",val.toString(),!1),val=this.get("enableThemeVideos",!1),val?"false"!==val:!browser.slow},UserSettings.prototype.language=function(val){returnnull!=val&&this.set("language",val.toString(),!1),this.get("language",!1)},UserSettings.prototype.skipBackLength=function(val){returnnull!=val&&this.set("skipBackLength",val.toString()),parseInt(this.get("skipBackLength")||"15000")},UserSettings.prototype.skipForwardLength=function(val){returnnull!=val&&this.set("skipForwardLength",val.toString()),parseInt(this.get("skipForwardLength")||"15000")},UserSettings.prototype.loadQuerySettings=function(query,context){varkey=getSavedQueryKey(context),values=this.get(key);if(values)returnvalues=JSON.parse(values),Object.assign(query,values)},UserSettings.prototype.saveQuerySettings=function(query,context){varkey=getSavedQueryKey(context),values={};query.SortBy&&(values.SortBy=query.SortBy),query.SortOrder&&(values.SortOrder=query.SortOrder),this.set(key,JSON.stringify(values))},UserSettings});