define(["appRouter","appHeader","globalize","loading","appSettings","pluginManager","focusManager","layoutManager","emby-scroller","paper-icon-button-light","listViewStyle","emby-button","material-icons"],function(appRouter,appHeader,globalize,loading,appSettings,pluginManager,focusManager,layoutManager){"use strict";return function(view,params){function editPlayer(id){var url=pluginManager.mapRoute("externalplayer","externalplayer.html");id&&(url+="?id="+id),appRouter.show(url)}function getPlayerHtml(player){var html="",icon="live_tv";"Game"===player.mediaType?icon="games":"Audio"===player.mediaType&&(icon="audiotrack");var tagName=layoutManager.tv?"button":"div";return html+="<"+tagName+' class="playerItem '+(layoutManager.tv?"listItem btnOptions playerItem":"listItem playerItem")+'" data-id="'+(player.id||"")+'">',html+='<i class="md-icon listItemIcon">'+icon+"</i>",html+='<div class="listItemBody">',player.mediaType&&(html+="<div>",html+=globalize.translate(player.mediaType),html+="</div>"),player.path&&(html+='<div class="secondary">',html+=player.path,html+="</div>"),html+="</div>",layoutManager.tv||(html+='<button type="button" is="paper-icon-button-light" class="btnOptions"><i class="md-icon">more_vert</i></button>'),html+="</"+tagName+">"}function loadPlayers(){var html=getPlayers().map(getPlayerHtml).join("");view.querySelector(".players").innerHTML=html,focusManager.autoFocus(view)}function getPlayers(){return JSON.parse(appSettings.get("externalplayers")||"[]")}view.querySelector(".btnAdd").addEventListener("click",function(){editPlayer()}),view.querySelector(".players").addEventListener("click",function(e){var btnOptions,playerItem=e.target.closest(".playerItem");playerItem&&(btnOptions=e.target.closest(".btnOptions"),(layoutManager.tv||btnOptions)&&function(playerId){if(!getPlayers().filter(function(p){return p.id===playerId})[0])return;require(["actionsheet"],function(actionsheet){var menuItems=[];menuItems.push({name:globalize.translate("Edit"),id:"edit"}),menuItems.push({name:globalize.translate("Delete"),id:"delete"}),actionsheet.show({items:menuItems,title:globalize.translate("ExternalPlayer")}).then(function(id){switch(id){case"edit":editPlayer(playerId);break;case"delete":!function(id){var players=getPlayers().filter(function(p){return p.id!==id});appSettings.set("externalplayers",JSON.stringify(players)),loadPlayers()}(playerId)}})})}(playerItem.getAttribute("data-id")))}),view.addEventListener("viewshow",function(e){e.detail.isRestored;appHeader.setTitle(globalize.translate("ExternalPlayers")),loading.hide(),loadPlayers()})}});