define(["exports"],function(_exports){Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0;var currentId=0;function addUniquePlaylistItemId(item){item.PlaylistItemId||(item.PlaylistItemId="playlistItem"+currentId,currentId++)}function PlayQueueManager(){this._playlist=[],this._repeatMode="RepeatNone"}PlayQueueManager.prototype.getPlaylistResult=function(options){var startIndex,limit;options&&(startIndex=options.StartIndex,limit=options.Limit);var original=this._playlist,playlist=original.slice(startIndex||0),total=original.length;return limit&&playlist.length>limit&&(playlist.length=limit),{Items:playlist,TotalRecordCount:total}},PlayQueueManager.prototype.getPlaylist=function(){return this._playlist.slice(0)},PlayQueueManager.prototype.setPlaylist=function(items){for(var i=0,length=(items=items.slice(0)).length;i<length;i++)addUniquePlaylistItemId(items[i]);this._currentPlaylistItemId=null,this._currentPlaylistIndex=-1,this._playlist=items,this._repeatMode="RepeatNone"},PlayQueueManager.prototype.queue=function(items){for(var i=0,length=items.length;i<length;i++)addUniquePlaylistItemId(items[i]),this._playlist.push(items[i])},PlayQueueManager.prototype.queueNext=function(items){for(var i=0,length=items.length;i<length;i++)addUniquePlaylistItemId(items[i]);var destArray,arrayToInsert,args,currentIndex=this.getCurrentPlaylistIndex();-1===currentIndex?currentIndex=this._playlist.length:currentIndex++,destArray=this._playlist,arrayToInsert=items,(args=[]).push(currentIndex),args.push(0),args=args.concat(arrayToInsert),destArray.splice.apply(destArray,args)},PlayQueueManager.prototype.getCurrentPlaylistLength=function(){return this._playlist.length},PlayQueueManager.prototype.getCurrentPlaylistIndex=function(){return this._currentPlaylistIndex},PlayQueueManager.prototype.getCurrentItem=function(){var index=this._currentPlaylistIndex;return-1===index?null:this._playlist[index]},PlayQueueManager.prototype.getCurrentPlaylistItemId=function(){return this._currentPlaylistItemId},PlayQueueManager.prototype.setPlaylistState=function(playlistItemId,playlistIndex){this._currentPlaylistItemId=playlistItemId,null==playlistIndex?this.refreshPlaylistIndex(playlistItemId):this._currentPlaylistIndex=playlistIndex},PlayQueueManager.prototype.refreshPlaylistIndex=function(playlistItemId){this._currentPlaylistIndex=function(playlistItemId,list){for(var i=0,length=list.length;i<length;i++)if(list[i].PlaylistItemId===playlistItemId)return i;return-1}(playlistItemId||this._currentPlaylistItemId,this._playlist)},PlayQueueManager.prototype.setPlaylistIndex=function(playlistIndex){playlistIndex<0?this.setPlaylistState(null):this.setPlaylistState(this._playlist[playlistIndex].PlaylistItemId)},PlayQueueManager.prototype.removeFromPlaylist=function(playlistItemIds){var playlist=this.getPlaylist();if(playlist.length<=playlistItemIds.length)return{result:"empty"};var currentPlaylistItemId=this.getCurrentPlaylistItemId(),isCurrentIndex=-1!==playlistItemIds.indexOf(currentPlaylistItemId);return this._playlist=playlist.filter(function(item){return!playlistItemIds.includes(item.PlaylistItemId)}),this.refreshPlaylistIndex(),{result:"removed",isCurrentIndex:isCurrentIndex}},PlayQueueManager.prototype.movePlaylistItem=function(playlistItemId,newIndex){for(var oldIndex,array,from,to,playlist=this.getPlaylist(),i=0,length=playlist.length;i<length;i++)if(playlist[i].PlaylistItemId===playlistItemId){oldIndex=i;break}if(-1===oldIndex||oldIndex===newIndex)return{result:"noop"};if(newIndex>=playlist.length)throw new Error("newIndex out of bounds");return from=oldIndex,to=newIndex,(array=playlist).splice(to,0,array.splice(from,1)[0]),this._playlist=playlist,this.refreshPlaylistIndex(),{result:"moved",playlistItemId:playlistItemId,oldIndex:oldIndex,newIndex:newIndex}},PlayQueueManager.prototype.reset=function(){this._playlist=[],this._currentPlaylistItemId=null,this._currentPlaylistIndex=-1,this._repeatMode="RepeatNone"},PlayQueueManager.prototype.setRepeatMode=function(value){this._repeatMode=value},PlayQueueManager.prototype.getRepeatMode=function(){return this._repeatMode},PlayQueueManager.prototype.getNextItemInfo=function(){var newIndex,playlist=this.getPlaylist(),playlistLength=playlist.length;switch(this.getRepeatMode()){case"RepeatOne":newIndex=this.getCurrentPlaylistIndex();break;case"RepeatAll":playlistLength<=(newIndex=this.getCurrentPlaylistIndex()+1)&&(newIndex=0);break;default:newIndex=this.getCurrentPlaylistIndex()+1}if(newIndex<0||playlistLength<=newIndex)return null;var item=playlist[newIndex];return item?{item:item,index:newIndex}:null},_exports.default=PlayQueueManager});