define(["browser","appStorage","apphost","loading","connectionManager","globalize","embyRouter","dom","css!./multiselect"],function(browser,appStorage,appHost,loading,connectionManager,globalize,embyRouter,dom){"use strict";function hideSelections(){var selectionCommandsPanel=currentSelectionCommandsPanel;if(selectionCommandsPanel){selectionCommandsPanel.parentNode.removeChild(selectionCommandsPanel),currentSelectionCommandsPanel=null,selectedItems=[],selectedElements=[];for(var elems=document.querySelectorAll(".itemSelectionPanel"),i=0,length=elems.length;i";var chkItemSelect=itemSelectionPanel.querySelector(".chkItemSelect");chkItemSelect.addEventListener("change",onSelectionChange)}}function showSelectionCommands(){var selectionCommandsPanel=currentSelectionCommandsPanel;if(!selectionCommandsPanel){selectionCommandsPanel=document.createElement("div"),selectionCommandsPanel.classList.add("selectionCommandsPanel"),document.body.appendChild(selectionCommandsPanel),currentSelectionCommandsPanel=selectionCommandsPanel;var html="";html+='',html+='

';var moreIcon="dots-horiz"===appHost.moreIcon?"":"";html+='",selectionCommandsPanel.innerHTML=html,selectionCommandsPanel.querySelector(".btnCloseSelectionPanel").addEventListener("click",hideSelections);var btnSelectionPanelOptions=selectionCommandsPanel.querySelector(".btnSelectionPanelOptions");btnSelectionPanelOptions.addEventListener("click",showMenuForSelectedItems)}}function deleteItems(apiClient,itemIds){return new Promise(function(resolve,reject){var msg=globalize.translate("sharedcomponents#ConfirmDeleteItem"),title=globalize.translate("sharedcomponents#HeaderDeleteItem");itemIds.length>1&&(msg=globalize.translate("sharedcomponents#ConfirmDeleteItems"),title=globalize.translate("sharedcomponents#HeaderDeleteItems")),require(["confirm"],function(confirm){confirm(msg,title).then(function(){var promises=itemIds.map(function(itemId){apiClient.deleteItem(itemId)});Promise.all(promises).then(resolve)},reject)})})}function showMenuForSelectedItems(e){var apiClient=connectionManager.currentApiClient();apiClient.getCurrentUser().then(function(user){var menuItems=[];menuItems.push({name:globalize.translate("sharedcomponents#AddToCollection"),id:"addtocollection",ironIcon:"add"}),menuItems.push({name:globalize.translate("sharedcomponents#AddToPlaylist"),id:"playlist",ironIcon:"playlist-add"}),user.Policy.EnableContentDeletion&&menuItems.push({name:globalize.translate("sharedcomponents#Delete"),id:"delete",ironIcon:"delete"}),user.Policy.EnableContentDownloading&&appHost.supports("filedownload"),menuItems.push({name:globalize.translate("sharedcomponents#GroupVersions"),id:"groupvideos",ironIcon:"call-merge"}),user.Policy.EnableSync&&appHost.supports("sync")&&menuItems.push({name:globalize.translate("sharedcomponents#MakeAvailableOffline"),id:"synclocal"}),menuItems.push({name:globalize.translate("sharedcomponents#MarkPlayed"),id:"markplayed"}),menuItems.push({name:globalize.translate("sharedcomponents#MarkUnplayed"),id:"markunplayed"}),menuItems.push({name:globalize.translate("sharedcomponents#Refresh"),id:"refresh"}),user.Policy.EnableSync&&menuItems.push({name:globalize.translate("sharedcomponents#SyncToOtherDevice"),id:"sync"}),require(["actionsheet"],function(actionsheet){actionsheet.show({items:menuItems,positionTo:e.target,callback:function(id){var items=selectedItems.slice(0),serverId=apiClient.serverInfo().Id;switch(id){case"addtocollection":require(["collectionEditor"],function(collectionEditor){(new collectionEditor).show({items:items,serverId:serverId})}),hideSelections(),dispatchNeedsRefresh();break;case"playlist":require(["playlistEditor"],function(playlistEditor){(new playlistEditor).show({items:items,serverId:serverId})}),hideSelections(),dispatchNeedsRefresh();break;case"delete":deleteItems(apiClient,items).then(function(){embyRouter.goHome()}),hideSelections(),dispatchNeedsRefresh();break;case"groupvideos":combineVersions(apiClient,items);break;case"markplayed":items.forEach(function(itemId){apiClient.markPlayed(apiClient.getCurrentUserId(),itemId)}),hideSelections(),dispatchNeedsRefresh();break;case"markunplayed":items.forEach(function(itemId){apiClient.markUnplayed(apiClient.getCurrentUserId(),itemId)}),hideSelections(),dispatchNeedsRefresh();break;case"refresh":require(["refreshDialog"],function(refreshDialog){new refreshDialog({itemIds:items,serverId:serverId}).show()}),hideSelections(),dispatchNeedsRefresh();break;case"sync":require(["syncDialog"],function(syncDialog){syncDialog.showMenu({items:items.map(function(i){return{Id:i}}),serverId:serverId})}),hideSelections(),dispatchNeedsRefresh();break;case"synclocal":require(["syncDialog"],function(syncDialog){syncDialog.showMenu({items:items.map(function(i){return{Id:i}}),isLocalSync:!0,serverId:serverId})}),hideSelections(),dispatchNeedsRefresh()}}})})})}function dispatchNeedsRefresh(){var elems=[];[].forEach.call(selectedElements,function(i){var container=dom.parentWithAttribute(i,"is","emby-itemscontainer");container&&elems.indexOf(container)===-1&&elems.push(container)});for(var i=0,length=elems.length;i=10&&onMouseOut(e)}}function onTouchEnd(e){onMouseOut(e)}function onMouseDown(e){touchStartTimeout&&(clearTimeout(touchStartTimeout),touchStartTimeout=null),touchTarget=e.target,touchStartTimeout=setTimeout(onTouchStartTimerFired,550)}function onMouseOut(e){touchStartTimeout&&(clearTimeout(touchStartTimeout),touchStartTimeout=null),touchTarget=null}function onTouchStartTimerFired(){if(touchTarget){var card=dom.parentWithClass(touchTarget,"card");touchTarget=null,card&&showSelections(card)}}function initTapHold(element){browser.touch&&!browser.safari?element.addEventListener("contextmenu",onTapHold):(dom.addEventListener(element,"touchstart",onTouchStart,{passive:!0}),dom.addEventListener(element,"touchmove",onTouchMove,{passive:!0}),dom.addEventListener(element,"touchend",onTouchEnd,{passive:!0}),dom.addEventListener(element,"touchcancel",onTouchEnd,{passive:!0}),dom.addEventListener(element,"mousedown",onMouseDown,{passive:!0}),dom.addEventListener(element,"mouseleave",onMouseOut,{passive:!0}),dom.addEventListener(element,"mouseup",onMouseOut,{passive:!0}))}var touchTarget,touchStartTimeout,touchStartX,self=this,container=options.container;initTapHold(container),options.bindOnClick!==!1&&container.addEventListener("click",onContainerClick),self.onContainerClick=onContainerClick,self.destroy=function(){container.removeEventListener("click",onContainerClick),container.removeEventListener("contextmenu",onTapHold);var element=container;dom.removeEventListener(element,"touchstart",onTouchStart,{passive:!0}),dom.removeEventListener(element,"touchmove",onTouchMove,{passive:!0}),dom.removeEventListener(element,"touchend",onTouchEnd,{passive:!0}),dom.removeEventListener(element,"mousedown",onMouseDown,{passive:!0}),dom.removeEventListener(element,"mouseleave",onMouseOut,{passive:!0}),dom.removeEventListener(element,"mouseup",onMouseOut,{passive:!0})}}});