define(["connectionManager","libraryMenu","loading","libraryBrowser","listView","cardBuilder","imageLoader","apphost","globalize","emby-itemscontainer"],function(connectionManager,libraryMenu,loading,libraryBrowser,listView,cardBuilder,imageLoader,appHost,globalize){"use strict";return function(view,params){function addCurrentItemToQuery(query,item){params.parentId&&(query.ParentId=params.parentId),"Person"==item.Type?query.PersonIds=item.Id:"Genre"==item.Type?query.GenreIds=item.Id:"MusicGenre"==item.Type?query.GenreIds=item.Id:"GameGenre"==item.Type?query.GenreIds=item.Id:"Studio"==item.Type?query.StudioIds=item.Id:"MusicArtist"==item.Type?query.ArtistIds=item.Id:query.ParentId=item.Id}function getQuery(parentItem){var key=getSavedQueryKey(),pageData=data[key];if(!pageData){pageData=data[key]={query:{SortBy:"SortName",SortOrder:"Ascending",Recursive:"false"!==params.recursive,Fields:"PrimaryImageAspectRatio,SortName,BasicSyncInfo",ImageTypeLimit:1,EnableImageTypes:"Primary,Backdrop,Banner,Thumb",StartIndex:0,Limit:libraryBrowser.getDefaultPageSize()}};var type=params.type;type&&(pageData.query.IncludeItemTypes=type,"Audio"==type&&(pageData.query.SortBy="Album,SortName"));var filters=params.filters;type&&(pageData.query.Filters=filters),parentItem&&addCurrentItemToQuery(pageData.query,parentItem),libraryBrowser.loadSavedQueryValues(key,pageData.query)}return pageData.query}function getSavedQueryKey(){return libraryBrowser.getSavedQueryKey()}function onViewStyleChange(parentItem){var query=getQuery(parentItem),itemsContainer=view.querySelector("#items");"Audio"==query.IncludeItemTypes?(itemsContainer.classList.add("vertical-list"),itemsContainer.classList.remove("vertical-wrap")):(itemsContainer.classList.remove("vertical-list"),itemsContainer.classList.add("vertical-wrap"))}function getPromise(parentItem){var query=getQuery(parentItem);return"nextup"===params.type?apiClient.getNextUpEpisodes({Limit:query.Limit,Fields:"PrimaryImageAspectRatio,SeriesInfo,DateCreated,BasicSyncInfo",UserId:apiClient.getCurrentUserId(),ImageTypeLimit:1,EnableImageTypes:"Primary,Backdrop,Thumb",EnableTotalRecordCount:!1}):apiClient.getItems(apiClient.getCurrentUserId(),query)}function reloadItems(parentItem){loading.show(),getPromise(parentItem).then(function(result){function onNextPageClick(){query.StartIndex+=query.Limit,reloadItems(view)}function onPreviousPageClick(){query.StartIndex-=query.Limit,reloadItems(view)}window.scrollTo(0,0);var i,length,elems,query=getQuery(parentItem),html="",pagingHtml=libraryBrowser.getQueryPagingHtml({startIndex:query.StartIndex,limit:query.Limit,totalRecordCount:result.TotalRecordCount,showLimit:!1});for(elems=view.querySelectorAll(".paging"),i=0,length=elems.length;i