define(["playbackManager","layoutManager","cardBuilder","focusManager","css!./tvplayqueue"],function(playbackManager,layoutManager,cardBuilder,focusManager){"use strict";function fetchPlaylistItems(){return this.empty?Promise.resolve([]):playbackManager.getPlaylist(this.currentPlayer)}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"></div></div>'}(parent),this.playlistElement=parent.querySelector(".osdPlaylist"),this.itemsContainer=parent.querySelector(".itemsContainer"),this.itemsContainer.fetchData=fetchPlaylistItems.bind(this),this.itemsContainer.getItemsHtml=function(items){return cardBuilder.getCardsHtml({items:items,action:"setplaylistindex",shape:"autooverflow",showTitle:!0,showParentTitle:!0,showYear:!0,lines:2,overlayText:!1,centerText:!0,cardLayout:!1,playlistItemId:this.playlistItemId,cardClass:"tvPlayQueueCard"})}.bind(this),this.itemsContainer.afterRefresh=function(){var playlistItemId=this.playlistItemId;if(playlistItemId){var card=this.itemsContainer.querySelector('.card[data-playlistItemId="'+playlistItemId+'"]');card&&focusManager.focus(card)}}.bind(this),this.itemsContainer.focus=function(){var playlistItemId=this.playlistItemId,card=this.itemsContainer.querySelector('.card[data-playlistItemId="'+playlistItemId+'"]');card?focusManager.focus(card):focusManager.autoFocus(this.itemsContainer)}.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.playlistIndex=playlistIndex,this.refreshItems(),parent.classList.remove("hide")):(parent.classList.add("hide"),this.empty=!0,this.playlistItemId=null,this.playlistIndex=-1,this.refreshItems())},OsdPlayQueue.prototype.onPlaybackStopped=function(){this.empty=!0,this.playlistItemId=null,this.playlistIndex=-1,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){this.playlistIndex=playbackManager.getCurrentPlaylistIndex(player),fetchPlaylistItems.call(this)},OsdPlayQueue.prototype.onPlaylistItemRemoved=function(player,e,info){for(var playlistItemIds=info.playlistItemIds,parent=this.options.parent,i=0,length=playlistItemIds.length;i<length;i++){var listItem=parent.querySelector('.listItem[data-playlistItemId="'+playlistItemIds[i]+'"]');listItem&&listItem.parentNode.removeChild(listItem)}this.playlistIndex=playbackManager.getCurrentPlaylistIndex(player),fetchPlaylistItems.call(this)},OsdPlayQueue.prototype.onInputCommand=function(e){return!1},OsdPlayQueue.prototype.pause=function(){this.itemsContainer.pause()},OsdPlayQueue.prototype.resume=function(options){this.itemsContainer.resume(options)},OsdPlayQueue.prototype.setBackdropItems=function(items){},OsdPlayQueue.prototype.destroy=function(){var options=this.options;if(options){var parent=options.parent;parent&&(parent.innerHTML="",parent.classList.add("hide"))}this.options=null,this.currentPlayer=null,this.itemsContainer=null},OsdPlayQueue});