define(["exports","./../common/globalize.js","./../common/playback/playbackmanager.js","./../approuter.js","./../loading/loading.js","./../emby-apiclient/events.js","./../common/servicelocator.js"],function(_exports,_globalize,_playbackmanager,_approuter,_loading,_events,_servicelocator){var currentItem;function showDialog(options){return Emby.importModule("./modules/dialog/dialog.js").then(function(dialog){return dialog(options)})}function mirrorIfEnabled(item){var currentPlayer;item?currentItem=item:item=currentItem,!item||item.IsFolder&&"Series"!==item.Type&&"MusicAlbum"!==item.Type&&"MusicArtist"!==item.Type||(currentPlayer=_playbackmanager.default.getCurrentPlayer())&&!currentPlayer.isLocalPlayer&&_playbackmanager.default.displayContent({ItemName:item.Name,ItemId:item.Id,ItemType:item.Type},currentPlayer)}function emptyCallback(){}Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0,document.addEventListener("itemshow",function(e){e=e.detail.item;e&&e.ServerId&&mirrorIfEnabled(e)}),_events.default.on(_playbackmanager.default,"pairing",function(e){_loading.default.show()}),_events.default.on(_playbackmanager.default,"paired",function(e){_loading.default.hide()}),_events.default.on(_playbackmanager.default,"pairerror",function(e){_loading.default.hide()}),_exports.default={show:function(button){var playerInfo,items,currentDeviceName,currentPlayerId,currentPlayerInfo=_playbackmanager.default.getPlayerInfo();currentPlayerInfo&&!currentPlayerInfo.isLocalPlayer?(items=[],playerInfo={title:currentDeviceName=(playerInfo=currentPlayerInfo).deviceName||playerInfo.name},items.push({name:_globalize.default.translate("HeaderRemoteControl"),id:"remote"}),items.push({name:_globalize.default.translate("Disconnect"),id:"disconnect"}),items.push({name:_globalize.default.translate("Cancel"),id:"cancel",type:"cancel"}),playerInfo.buttons=items,showDialog(playerInfo).then(function(result){return"remote"===result?_approuter.default.showNowPlaying():("disconnect"===result&&function(currentDeviceName){{var menuItems;-1!==_playbackmanager.default.getSupportedCommands().indexOf("EndSession")?((menuItems=[]).push({name:_globalize.default.translate("Yes"),id:"yes"}),menuItems.push({name:_globalize.default.translate("No"),id:"no"}),showDialog({buttons:menuItems,text:_globalize.default.translate("ConfirmEndPlayerSession",currentDeviceName)}).then(function(id){switch(id){case"yes":_playbackmanager.default.getCurrentPlayer().endSession(),_playbackmanager.default.setDefaultPlayerActive();break;case"no":_playbackmanager.default.setDefaultPlayerActive()}},emptyCallback)):_playbackmanager.default.setDefaultPlayerActive()}}(currentDeviceName),Promise.resolve())},emptyCallback)):(currentPlayerId=currentPlayerInfo?currentPlayerInfo.id:null,_loading.default.show(),_playbackmanager.default.getTargets().then(function(targets){var options,menuItems=targets.map(function(t){var target;return{name:t.name,nameSubtitle:t.appName,id:t.id,selected:currentPlayerId===t.id,secondaryText:(target=t).user?target.user.Name:null,icon:function(target){switch(target.deviceType||"tv"){case"smartphone":return"&#xE32C;";case"tablet":return"&#xE32F;";case"tv":return"&#xE333;";case"cast":return"&#xE307;";case"desktop":return"&#xE30A;";default:return"&#xE333;"}}(t)}}),menuItems=(_loading.default.hide(),{title:_globalize.default.translate("HeaderPlayOn"),items:menuItems,positionTo:button,positionY:"bottom",resolveOnClick:!0,iconRight:!1,hasItemIcon:!0,showNameSubtitle:!0});_servicelocator.appHost.supports("castmenuhashchange")&&!function(){for(var brands=(navigator.userAgentData||{}).brands||[],i=0,length=brands.length;i<length;i++)if("chromium"===(brands[i].brand||"").toLowerCase())return 1}()||(menuItems.enableHistory=!1),options=menuItems,Emby.importModule("./modules/actionsheet/actionsheet.js").then(function(ActionSheet){return ActionSheet.show(options)}).then(function(id){var target=targets.filter(function(t){return t.id===id})[0];_playbackmanager.default.trySetActivePlayer(target.playerName,target),mirrorIfEnabled()},emptyCallback)}))}}});