define(["playbackManager","cardBuilder","focusManager","css!./tvplayqueue"],function(playbackManager,cardBuilder,focusManager){"use strict";function fetchPlaylistItems(query){return this.empty?Promise.resolve([]):playbackManager.getPlaylist(query||{},this.currentPlayer)}function scrollOrFocus(instance,focus){var playlistIndex=playbackManager.getCurrentPlaylistIndex(instance.currentPlayer);null==playlistIndex&&(playlistIndex=0),instance.itemsContainer.scrollToIndex(playlistIndex,{},focus)}function OsdPlayQueue(options){var parent=(this.options=options).parent;!function(parent){parent.innerHTML='<div is="emby-scroller" class="padded-top-focusscale padded-bottom-focusscale tvPlayQueueScroller" data-mousewheel="false" data-centerfocus="true"><div is="emby-itemscontainer" class="scrollSlider focuscontainer-x padded-left padded-right itemsContainer focusable" data-skipplaycommands="true" data-virtualscrolllayout="horizontal-grid"></div></div>'}(parent),this.playlistElement=parent.querySelector(".osdPlaylist"),this.itemsContainer=parent.querySelector(".itemsContainer"),this.itemsContainer.fetchData=fetchPlaylistItems.bind(this),this.itemsContainer.getListOptions=function(items){return{renderer:cardBuilder,options:{action:"setplaylistindex",shape:"autooverflow",showParentTitle:!0,fields:["Name","ProductionYear"],lines:2,overlayText:!1,centerText:!0,cardLayout:!1,playlistItemId:this.playlistItemId,cardClass:"tvPlayQueueCard",multiSelect:!1},virtualScrollLayout:"horizontal-grid"}}.bind(this),this.itemsContainer.afterRefresh=function(){document.activeElement,scrollOrFocus(this,!0)}.bind(this),this.itemsContainer.focus=function(){scrollOrFocus(this,!0)}.bind(this),this.itemsContainer.addEventListener("action-remove",function(e){playbackManager.removeFromPlaylist([e.detail.playlistItemId],this.currentPlayer)}.bind(this))}return OsdPlayQueue.prototype.updatePlaylist=function(player,playlistItemId,playlistIndex,playlistLength){this.currentPlayer=player;var parent=this.options.parent;0<playlistLength?(this.empty=!1,this.playlistItemId=playlistItemId,this.refreshItems(),parent.classList.remove("hide")):(parent.classList.add("hide"),this.empty=!0,this.playlistItemId=null,this.refreshItems())},OsdPlayQueue.prototype.onPlaybackStopped=function(){this.empty=!0,this.playlistItemId=null,this.refreshItems()},OsdPlayQueue.prototype.refreshItems=function(){this.itemsContainer.refreshItems?this.itemsContainer.refreshItems():setTimeout(this.refreshItems.bind(this),100)},OsdPlayQueue.prototype.onPlaylistItemMoved=function(player,e,info){fetchPlaylistItems.call(this)},OsdPlayQueue.prototype.onPlaylistItemRemoved=function(player,e,info){this.itemsContainer.refreshItems()},OsdPlayQueue.prototype.setPausedState=function(paused){var elem=this.options.parent.querySelector(".activePlaylistCardBox");elem&&(paused?elem.classList.add("paused"):elem.classList.remove("paused"))},OsdPlayQueue.prototype.onInputCommand=function(e){return!1},OsdPlayQueue.prototype.pause=function(){this.itemsContainer.pause()},OsdPlayQueue.prototype.resume=function(options){return this.itemsContainer.resume(options)},OsdPlayQueue.prototype.setBackdropItems=function(items){},OsdPlayQueue.prototype.destroy=function(){var parent,options=this.options;!options||(parent=options.parent)&&(parent.innerHTML="",parent.classList.add("hide")),this.options=null,this.currentPlayer=null,this.itemsContainer=null},OsdPlayQueue});