define([],function(){"use strict";functionaddUniquePlaylistItemId(item){item.PlaylistItemId||(item.PlaylistItemId="playlistItem"+currentId,currentId++)}functionfindPlaylistIndex(playlistItemId,list){for(vari=0,length=list.length;i<length;i++)if(list[i].PlaylistItemId===playlistItemId)returni;return-1}functionPlayQueueManager(){this._playlist=[],this._repeatMode="RepeatNone"}functionmoveInArray(array,from,to){array.splice(to,0,array.splice(from,1)[0])}varcurrentId=0;returnPlayQueueManager.prototype.getPlaylist=function(){returnthis._playlist.slice(0)},PlayQueueManager.prototype.setPlaylist=function(items){items=items.slice(0);for(vari=0,length=items.length;i<length;i++)addUniquePlaylistItemId(items[i]);this._currentPlaylistItemId=null,this._playlist=items,this._repeatMode="RepeatNone"},PlayQueueManager.prototype.queue=function(items){for(vari=0,length=items.length;i<length;i++)addUniquePlaylistItemId(items[i]),this._playlist.push(items[i])},PlayQueueManager.prototype.queueNext=function(items){this.queue(items)},PlayQueueManager.prototype.getCurrentPlaylistIndex=function(){returnfindPlaylistIndex(this.getCurrentPlaylistItemId(),this._playlist)},PlayQueueManager.prototype.getCurrentItem=function(){varindex=findPlaylistIndex(this.getCurrentPlaylistItemId(),this._playlist);returnindex===-1?null:this._playlist[index]},PlayQueueManager.prototype.getCurrentPlaylistItemId=function(){returnthis._currentPlaylistItemId},PlayQueueManager.prototype.setPlaylistState=function(playlistItemId,playlistIndex){this._currentPlaylistItemId=playlistItemId},PlayQueueManager.prototype.setPlaylistIndex=function(playlistIndex){playlistIndex<0?this.setPlaylistState(null):this.setPlaylistState(this._playlist[playlistIndex].PlaylistItemId)},PlayQueueManager.prototype.removeFromPlaylist=function(playlistItemIds){varplaylist=this.getPlaylist();if(playlist.length<=playlistItemIds.length)return{result:"empty"};varcurrentPlaylistItemId=this.getCurrentPlaylistItemId(),isCurrentIndex=playlistItemIds.indexOf(currentPlaylistItemId)!==-1;returnthis._playlist=playlist.filter(function(item){returnplaylistItemIds.indexOf(item.PlaylistItemId)===-1}),{result:"removed",isCurrentIndex:isCurrentIndex}},PlayQueueManager.prototype.movePlaylistItem=function(playlistItemId,newIndex){for(varoldIndex,playlist=this.getPlaylist(),i=0,length=playlist.length;i<length;i++)if(playlist[i].PlaylistItemId===playlistItemId){oldIndex=i;break}if(oldIndex===-1||oldIndex===newIndex)return{result:"noop"};if(newIndex>=playlist.length)thrownewError("newIndex out of bounds");returnmoveInArray(playlist,oldIndex,newIndex),this._playlist=playlist,{result:"moved",playlistItemId:playlistItemId,newIndex:newIndex}},PlayQueueManager.prototype.reset=function(){this._playlist=[],this._currentPlaylistItemId=null,this._repeatMode="RepeatNone"},PlayQueueManager.prototype.setRepeatMode=function(value){this._repeatMode=value},PlayQueueManager.prototype.getRepeatMode=function(){returnthis._repeatMode},PlayQueueManager.prototype.getNextItemInfo=function(){varnewIndex,playlist=this.getPlaylist(),playlistLength=playlist.length;switch(this.getRepeatMode()){case"RepeatOne":newIndex=this.getCurrentPlaylistIndex();break;case"RepeatAll":newIndex=this.getCurrentPlaylistIndex()+1,newIndex>=playlistLength&&(newIndex=0);break;default:newIndex=this.getCurrentPlaylistIndex()+1}if(newIndex<0||newIndex>=playlistLength)returnnull;varitem=playlist[newIndex];returnitem?{item:item,index:newIndex}:null},PlayQueueManager});