import playbackManager from"./../modules/common/playback/playbackmanager.js";import layoutManager from"./../modules/layoutmanager.js";import listView from"./../modules/listview/listview.js";import"./../modules/emby-elements/emby-scroller/emby-scroller.js";import"./../modules/emby-elements/emby-button/paper-icon-button-light.js";import"./../modules/emby-elements/emby-itemscontainer/emby-itemscontainer.js";function buildDefaultLayout(parent,options){return parent.insertAdjacentHTML("afterbegin",'
'),parent.querySelector(".osdPlayQueue")}function afterRefresh(){this.setScrollToTrack=!0,this.scrollToTrack&&(this.scrollToTrack=null,this.scrollCurrentTrackToTop())}function fetchPlaylistItems(query){var player=this.currentPlayer;return this.empty||!player?Promise.resolve({Items:[],TotalRecordCount:0}):playbackManager.getPlaylist(query||{},player)}function getPlaylistListOptions(items){return{renderer:listView,options:{smallIcon:!0,action:"setplaylistindex",playAction:"setplaylistindex",fields:["Name","ParentName"],enableUserDataButtons:!1,moreButton:!1,removeFromPlayQueueButton:!0,dragReorder:!layoutManager.tv,playQueueIndicator:!0,autoHideBorderOnTouch:!0,hideMoreButtonOnTouch:!0,autoMoveParentName:!0,buttonCommands:["removefromplayqueue"]},virtualScrollLayout:"vertical-list"}}function onPlaylistItemDrop(e){e.preventDefault();var newIndex=e.detail.newIndex,e=e.detail.items[0].PlaylistItemId;playbackManager.movePlaylistItem(e,newIndex,this.currentPlayer)}function OsdPlayQueue(options){(this.options=options).parent=buildDefaultLayout(options.parent,options);var parent=options.parent;this.playlistElement=options.parent,this.itemsContainer=parent.querySelector(".itemsContainer"),this.itemsContainer.fetchData=fetchPlaylistItems.bind(this),this.itemsContainer.afterRefresh=afterRefresh.bind(this),this.itemsContainer.getListOptions=getPlaylistListOptions.bind(this),this.itemsContainer.scrollResizeObserver=!0,this.itemsContainer.addEventListener("itemdrop",onPlaylistItemDrop.bind(this))}require(["css!videoosd/playqueue.css"]),OsdPlayQueue.prototype.scrollCurrentTrackToTop=function(){var itemsContainer,index=playbackManager.getCurrentPlaylistIndex(this.currentPlayer);-1!==index&&(itemsContainer=this.playlistElement.querySelector(".itemsContainer"))&&itemsContainer.scrollToIndex(index,{behavior:"instant",skipWhenVisibleY:!0},!1)},OsdPlayQueue.prototype.setPausedState=function(paused){var elem=this.playlistElement.querySelector(".playlistIndexIndicatorImage");elem&&(paused?elem.classList.add("playlistIndexIndicatorImage-paused"):elem.classList.remove("playlistIndexIndicatorImage-paused"))},OsdPlayQueue.prototype.updatePlaylist=function(player,playlistItemId,playlistIndex,playlistLength){this.currentPlayer=player,!1!==this.setScrollToTrack&&(this.scrollToTrack=!0),this.empty=!playlistLength,this.refreshItems()},OsdPlayQueue.prototype.onPlaybackStopped=function(){this.empty=!0,this.refreshItems()},OsdPlayQueue.prototype.refreshItems=function(){let itemsContainer=this.itemsContainer;if(itemsContainer)return itemsContainer.waitForCustomElementUpgrade().then(function(){itemsContainer.refreshItems()})},OsdPlayQueue.prototype.onPlaylistItemMoved=function(player,e,info){this.itemsContainer.refreshItems()},OsdPlayQueue.prototype.onPlaylistItemRemoved=function(player,e,info){this.itemsContainer.refreshItems()},OsdPlayQueue.prototype.pause=function(){this.paused=!0,this.itemsContainer.pause&&this.itemsContainer.pause()},OsdPlayQueue.prototype.resume=function(options){this.paused=!1;let itemsContainer=this.itemsContainer;return itemsContainer.waitForCustomElementUpgrade().then(function(){itemsContainer.resume(options)})},OsdPlayQueue.prototype.destroy=function(){var options=this.options;options&&(options=options.parent)&&options.remove(),this.options=null,this.currentPlayer=null,this.itemsContainer=null,this.playlistElement=null};export default OsdPlayQueue;