define(["backdrop","appStorage","libraryMenu"],function(backdrop,appStorage,libraryMenu){"use strict";functionenabled(){varapiClient=window.ApiClient;if(!apiClient)return!1;varuserId=apiClient.getCurrentUserId(),val=appStorage.getItem("enableBackdrops-"+userId);return"1"==val}functiongetBackdropItemIds(apiClient,userId,types,parentId){varkey="backdrops2_"+userId+(types||"")+(parentId||""),data=cache[key];if(data)returnconsole.log("Found backdrop id list in cache. Key: "+key),data=JSON.parse(data),Promise.resolve(data);varoptions={SortBy:"IsFavoriteOrLiked,Random",Limit:20,Recursive:!0,IncludeItemTypes:types,ImageTypes:"Backdrop",ParentId:parentId,EnableTotalRecordCount:!1};returnapiClient.getItems(apiClient.getCurrentUserId(),options).then(function(result){varimages=result.Items.map(function(i){return{Id:i.Id,tag:i.BackdropImageTags[0],ServerId:i.ServerId}});returncache[key]=JSON.stringify(images),images})}functionshowBackdrop(type,parentId){varapiClient=window.ApiClient;apiClient&&getBackdropItemIds(apiClient,apiClient.getCurrentUserId(),type,parentId).then(function(images){images.length?backdrop.setBackdrops(images.map(function(i){returni.BackdropImageTags=[i.tag],i})):backdrop.clear()})}varcache={};pageClassOn("pagebeforeshow","page",function(){varpage=this;if(!page.classList.contains("selfBackdropPage"))if(page.classList.contains("backdropPage"))if(enabled()){vartype=page.getAttribute("data-backdroptype"),parentId=page.classList.contains("globalBackdropPage")?"":libraryMenu.getTopParentId();showBackdrop(type,parentId)}elsepage.classList.remove("backdropPage"),backdrop.clear();elsebackdrop.clear()})});