define(["appSettings","events","browser"],function(appsettings,events,browser){"use strict";functionUserSettings(){functiononSaveTimeout(){saveTimeout=null,currentApiClient.updateDisplayPreferences("usersettings",displayPrefs,currentUserId,"emby")}functionsaveServerPreferences(){saveTimeout&&clearTimeout(saveTimeout),saveTimeout=setTimeout(onSaveTimeout,50)}varcurrentUserId,currentApiClient,displayPrefs,saveTimeout,self=this;self.setUserInfo=function(userId,apiClient){returnsaveTimeout&&clearTimeout(saveTimeout),currentUserId=userId,currentApiClient=apiClient,userId?apiClient.getDisplayPreferences("usersettings",userId,"emby").then(function(result){result.CustomPrefs=result.CustomPrefs||{},displayPrefs=result}):(displayPrefs=null,Promise.resolve())},self.getData=function(){returndisplayPrefs},self.importFrom=function(instance){displayPrefs=instance.getData()},self.set=function(name,value,enableOnServer){varuserId=currentUserId;if(!userId)thrownewError("userId cannot be null");varcurrentValue=self.get(name);appsettings.set(name,value,userId),enableOnServer!==!1&&displayPrefs&&(displayPrefs.CustomPrefs[name]=null==value?value:value.toString(),saveServerPreferences()),currentValue!==value&&events.trigger(self,"change",[name])},self.get=function(name,enableOnServer){varuserId=currentUserId;if(!userId)thrownewError("userId cannot be null");returnenableOnServer!==!1&&displayPrefs?displayPrefs.CustomPrefs[name]:appsettings.get(name,userId)},self.serverConfig=function(config){varapiClient=currentApiClient;returnconfig?apiClient.updateUserConfiguration(currentUserId,config):apiClient.getUser(currentUserId).then(function(user){returnuser.Configuration})},self.loadQuerySettings=function(){}}functiongetSavedQueryKey(context){return"query-"+context}returnUserSettings.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});