define(["browser","datetime","backdrop","libraryBrowser","listView","userdataButtons","imageLoader","playbackManager","nowPlayingHelper","events","connectionManager","apphost","globalize","cardStyle","emby-itemscontainer","css!css/nowplaying.css"],function(browser,datetime,backdrop,libraryBrowser,listView,userdataButtons,imageLoader,playbackManager,nowPlayingHelper,events,connectionManager,appHost,globalize){"use strict";function showAudioMenu(context,player,button,item){var currentIndex=playbackManager.getAudioStreamIndex(player),streams=playbackManager.audioTracks(player),menuItems=streams.map(function(s){var menuItem={name:s.DisplayTitle,id:s.Index};return s.Index==currentIndex&&(menuItem.selected=!0),menuItem});require(["actionsheet"],function(actionsheet){actionsheet.show({items:menuItems,positionTo:button,callback:function(id){playbackManager.setAudioStreamIndex(parseInt(id),player)}})})}function showSubtitleMenu(context,player,button,item){var currentIndex=playbackManager.getSubtitleStreamIndex(player),streams=playbackManager.subtitleTracks(player),menuItems=streams.map(function(s){var menuItem={name:s.DisplayTitle,id:s.Index};return s.Index==currentIndex&&(menuItem.selected=!0),menuItem});menuItems.unshift({id:-1,name:globalize.translate("ButtonOff"),selected:null==currentIndex}),require(["actionsheet"],function(actionsheet){actionsheet.show({items:menuItems,positionTo:button,callback:function(id){playbackManager.setSubtitleStreamIndex(parseInt(id),player)}})})}function getNowPlayingNameHtml(nowPlayingItem,includeNonNameInfo){var names=nowPlayingHelper.getNowPlayingNames(nowPlayingItem,includeNonNameInfo);return names.map(function(i){return i.text}).join("
")}function seriesImageUrl(item,options){if("Episode"!==item.Type)return null;if(options=options||{},options.type=options.type||"Primary","Primary"===options.type&&item.SeriesPrimaryImageTag)return options.tag=item.SeriesPrimaryImageTag,connectionManager.getApiClient(item.ServerId).getScaledImageUrl(item.SeriesId,options);if("Thumb"===options.type){if(item.SeriesThumbImageTag)return options.tag=item.SeriesThumbImageTag,connectionManager.getApiClient(item.ServerId).getScaledImageUrl(item.SeriesId,options);if(item.ParentThumbImageTag)return options.tag=item.ParentThumbImageTag,connectionManager.getApiClient(item.ServerId).getScaledImageUrl(item.ParentThumbItemId,options)}return null}function imageUrl(item,options){return options=options||{},options.type=options.type||"Primary",item.ImageTags&&item.ImageTags[options.type]?(options.tag=item.ImageTags[options.type],connectionManager.getApiClient(item.ServerId).getScaledImageUrl(item.PrimaryImageItemId||item.Id,options)):item.AlbumId&&item.AlbumPrimaryImageTag?(options.tag=item.AlbumPrimaryImageTag,connectionManager.getApiClient(item.ServerId).getScaledImageUrl(item.AlbumId,options)):null}function updateNowPlayingInfo(context,state){var item=state.NowPlayingItem,displayName=item?getNowPlayingNameHtml(item).replace("
"," - "):"";context.querySelector(".nowPlayingPageTitle").innerHTML=displayName,displayName.length>0?context.querySelector(".nowPlayingPageTitle").classList.remove("hide"):context.querySelector(".nowPlayingPageTitle").classList.add("hide");var url=item?seriesImageUrl(item,{maxHeight:300})||imageUrl(item,{maxHeight:300}):null;url!==currentImgUrl&&(setImageUrl(context,url),item?(backdrop.setBackdrops([item]),ApiClient.getItem(Dashboard.getCurrentUserId(),item.Id).then(function(fullItem){userdataButtons.fill({item:fullItem,includePlayed:!1,style:"icon",element:context.querySelector(".nowPlayingPageUserDataButtons")})})):(backdrop.clear(),userdataButtons.destroy({element:context.querySelector(".nowPlayingPageUserDataButtons")})))}function setImageUrl(context,url){currentImgUrl=url;var imgContainer=context.querySelector(".nowPlayingPageImageContainer");url?(imgContainer.innerHTML='',imgContainer.classList.remove("hide")):(imgContainer.classList.add("hide"),imgContainer.innerHTML="")}function buttonEnabled(btn,enabled){btn.disabled=!enabled}function buttonVisible(btn,enabled){enabled?btn.classList.remove("hide"):btn.classList.add("hide")}function updateSupportedCommands(context,commands){for(var all=context.querySelectorAll(".btnCommand"),i=0,length=all.length;i1&&supportedCommands.indexOf("SetAudioStreamIndex")!=-1)}function updateSubtitleTracksDisplay(player,context){var supportedCommands=currentPlayerSupportedCommands;buttonVisible(context.querySelector(".btnSubtitles"),playbackManager.subtitleTracks(player).length&&supportedCommands.indexOf("SetSubtitleStreamIndex")!=-1)}function updateRepeatModeDisplay(repeatMode){var context=dlg,toggleRepeatButton=context.querySelector(".repeatToggleButton");"RepeatAll"==repeatMode?(toggleRepeatButton.innerHTML="repeat",toggleRepeatButton.classList.add("nowPlayingPageRepeatActive")):"RepeatOne"==repeatMode?(toggleRepeatButton.innerHTML="repeat_one",toggleRepeatButton.classList.add("nowPlayingPageRepeatActive")):(toggleRepeatButton.innerHTML="repeat",toggleRepeatButton.classList.remove("nowPlayingPageRepeatActive"))}function updatePlayerVolumeState(context,isMuted,volumeLevel){var view=context,supportedCommands=currentPlayerSupportedCommands,showMuteButton=!0,showVolumeSlider=!0;supportedCommands.indexOf("Mute")===-1&&(showMuteButton=!1),supportedCommands.indexOf("SetVolume")===-1&&(showVolumeSlider=!1),currentPlayer.isLocalPlayer&&appHost.supports("physicalvolumecontrol")&&(showMuteButton=!1,showVolumeSlider=!1),isMuted?(view.querySelector(".buttonMute").setAttribute("title",globalize.translate("Unmute")),view.querySelector(".buttonMute i").innerHTML=""):(view.querySelector(".buttonMute").setAttribute("title",globalize.translate("Mute")),view.querySelector(".buttonMute i").innerHTML=""),showMuteButton?view.querySelector(".buttonMute").classList.remove("hide"):view.querySelector(".buttonMute").classList.add("hide");var nowPlayingVolumeSlider=context.querySelector(".nowPlayingVolumeSlider"),nowPlayingVolumeSliderContainer=context.querySelector(".nowPlayingVolumeSliderContainer");nowPlayingVolumeSlider&&(showVolumeSlider?nowPlayingVolumeSliderContainer.classList.remove("hide"):nowPlayingVolumeSliderContainer.classList.add("hide"),nowPlayingVolumeSlider.dragging||(nowPlayingVolumeSlider.value=volumeLevel||0))}function updatePlayPauseState(isPaused,isActive){var context=dlg,btnPlayPause=context.querySelector(".btnPlayPause");isPaused?btnPlayPause.querySelector("i").innerHTML="play_arrow":btnPlayPause.querySelector("i").innerHTML="pause",buttonVisible(btnPlayPause,isActive)}function updateTimeDisplay(positionTicks,runtimeTicks){var context=dlg,positionSlider=context.querySelector(".nowPlayingPositionSlider");if(positionSlider&&!positionSlider.dragging)if(runtimeTicks){var pct=positionTicks/runtimeTicks;pct*=100,positionSlider.value=pct}else positionSlider.value=0;null==positionTicks?context.querySelector(".positionTime").innerHTML="--:--":context.querySelector(".positionTime").innerHTML=datetime.getDisplayRunningTime(positionTicks),null!=runtimeTicks?context.querySelector(".runtime").innerHTML=datetime.getDisplayRunningTime(runtimeTicks):context.querySelector(".runtime").innerHTML="--:--"}function getPlaylistItems(player){return playbackManager.getPlaylist(player)}function loadPlaylist(context,player){getPlaylistItems(player).then(function(items){var html="";html+=listView.getListViewHtml({items:items,smallIcon:!0,action:"setplaylistindex",enableUserDataButtons:!1,rightButtons:[{icon:"",title:globalize.translate("ButtonRemove"),id:"remove"}],dragHandle:!0}),items.length?context.querySelector(".playlistSection").classList.remove("hide"):context.querySelector(".playlistSection").classList.add("hide");var itemsContainer=context.querySelector(".playlist");itemsContainer.innerHTML=html;var playlistItemId=playbackManager.getCurrentPlaylistItemId(player);if(playlistItemId){var img=itemsContainer.querySelector('.listItem[data-playlistItemId="'+playlistItemId+'"] .listItemImage');img&&(img.classList.remove("lazy"),img.classList.add("playlistIndexIndicatorImage"))}imageLoader.lazyChildren(itemsContainer)})}function onPlaybackStart(e,state){console.log("remotecontrol event: "+e.type);var player=this;onStateChanged.call(player,e,state)}function onRepeatModeChange(e){var player=this;updateRepeatModeDisplay(playbackManager.getRepeatMode(player))}function onPlaylistUpdate(e){var player=this;loadPlaylist(dlg,player)}function onPlaylistItemRemoved(e,info){for(var context=dlg,playlistItemIds=info.playlistItemIds,i=0,length=playlistItemIds.length;i