define(["cardBuilder","apphost","imageLoader","libraryBrowser","loading","emby-itemscontainer"],function(cardBuilder,appHost,imageLoader,libraryBrowser,loading){"use strict";return function(view,params){function getSavedQueryKey(){return libraryBrowser.getSavedQueryKey()}function reloadItems(page){loading.show();var promise="Recordings"==params.type?ApiClient.getLiveTvRecordings(query):"RecordingSeries"==params.type?ApiClient.getLiveTvRecordingSeries(query):"true"==params.IsAiring?ApiClient.getLiveTvRecommendedPrograms(query):ApiClient.getLiveTvPrograms(query);promise.then(function(result){function onNextPageClick(){query.StartIndex+=query.Limit,reloadItems(page)}function onPreviousPageClick(){query.StartIndex-=query.Limit,reloadItems(page)}window.scrollTo(0,0);var html="",pagingHtml=libraryBrowser.getQueryPagingHtml({startIndex:query.StartIndex,limit:query.Limit,totalRecordCount:result.TotalRecordCount,showLimit:!1});page.querySelector(".listTopPaging").innerHTML=pagingHtml,html=cardBuilder.getCardsHtml({items:result.Items,shape:query.IsMovie||"RecordingSeries"==params.type?"portrait":"backdrop",preferThumb:!query.IsMovie&&"RecordingSeries"!=params.type,inheritThumb:"Recordings"==params.type,context:"livetv",centerText:!0,lazy:!0,overlayText:!1,showTitle:!0,showParentTitle:query.IsSeries!==!1&&!query.IsMovie,showAirTime:"Recordings"!=params.type&&"RecordingSeries"!=params.type,showAirDateTime:"Recordings"!=params.type&&"RecordingSeries"!=params.type,showChannelName:"Recordings"!=params.type&&"RecordingSeries"!=params.type,overlayMoreButton:!0,showYear:query.IsMovie&&"Recordings"==params.type,showSeriesYear:"RecordingSeries"===params.type,coverImage:!0});var elem=page.querySelector(".itemsContainer");elem.innerHTML=html+pagingHtml,imageLoader.lazyChildren(elem);var i,length,elems;for(elems=page.querySelectorAll(".btnNextPage"),i=0,length=elems.length;i<length;i++)elems[i].addEventListener("click",onNextPageClick);for(elems=page.querySelectorAll(".btnPreviousPage"),i=0,length=elems.length;i<length;i++)elems[i].addEventListener("click",onPreviousPageClick);libraryBrowser.saveQueryValues(getSavedQueryKey(),query),loading.hide()})}var query={UserId:Dashboard.getCurrentUserId(),StartIndex:0,Fields:"ChannelInfo",Limit:libraryBrowser.getDefaultPageSize()};"Recordings"==params.type?(query.IsInProgress=!1,params.groupid&&(query.GroupId=params.groupid)):"RecordingSeries"==params.type?(query.SortOrder="SortName",query.SortOrder="Ascending"):(query.HasAired=!1,query.SortBy="StartDate,SortName",query.SortOrder="Ascending"),view.addEventListener("viewbeforeshow",function(){query.ParentId=LibraryMenu.getTopParentId();var page=this;"true"==params.IsMovie?query.IsMovie=!0:"false"==params.IsMovie&&(query.IsMovie=!1),"true"==params.IsSeries?query.IsSeries=!0:"false"==params.IsSeries&&(query.IsSeries=!1),"true"==params.IsNews?query.IsNews=!0:"false"==params.IsNews&&(query.IsNews=!1),"true"==params.IsSports?query.IsSports=!0:"false"==params.IsSports&&(query.IsSports=!1),"true"==params.IsKids?query.IsKids=!0:"false"==params.IsKids&&(query.IsKids=!1),"true"==params.IsAiring?query.IsAiring=!0:"false"==params.IsAiring&&(query.IsAiring=!1),"Recordings"==params.type?"true"==params.IsMovie?LibraryMenu.setTitle(Globalize.translate("TabMovies")):"true"==params.IsSports?LibraryMenu.setTitle(Globalize.translate("Sports")):"true"==params.IsKids?LibraryMenu.setTitle(Globalize.translate("HeaderForKids")):LibraryMenu.setTitle(Globalize.translate("TabRecordings")):"RecordingSeries"==params.type?LibraryMenu.setTitle(Globalize.translate("TabShows")):"true"==params.IsMovie?LibraryMenu.setTitle(Globalize.translate("HeaderUpcomingMovies")):"true"==params.IsSports?LibraryMenu.setTitle(Globalize.translate("HeaderUpcomingSports")):"true"==params.IsKids?LibraryMenu.setTitle(Globalize.translate("HeaderUpcomingForKids")):"true"==params.IsAiring?LibraryMenu.setTitle(Globalize.translate("HeaderOnNow")):LibraryMenu.setTitle(Globalize.translate("HeaderUpcomingPrograms"));var viewkey=getSavedQueryKey();libraryBrowser.loadSavedQueryValues(viewkey,query),reloadItems(page)})}});