define(["exports","./../common/globalize.js","./../common/playback/playbackmanager.js","./../loading/loading.js","./../emby-apiclient/events.js","./../common/servicelocator.js","./../browser.js","./../layoutmanager.js"],function(_exports,_globalize,_playbackmanager,_loading,_events,_servicelocator,_browser,_layoutmanager){var currentItem;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&&"chromecast"===currentPlayer.id&&_playbackmanager.default.displayContent({ItemName:item.Name,ItemId:item.Id,ItemType:item.Type},currentPlayer)}function emptyCallback(){}function getIcon(deviceType){switch(deviceType){case"smartphone":return"&#xe32C;";case"tablet":return"&#xe32F;";case"tv":return"&#xe333;";case"cast":return"&#xe307;";case"desktop":return"&#xe30A;";default:return"&#xe333;"}}Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.default=void 0;var LocalPlayerId="local";function switchToPlayer(id,target){id===LocalPlayerId?_playbackmanager.default.setDefaultPlayerActive():(_playbackmanager.default.trySetActivePlayer(target.playerName,target),mirrorIfEnabled())}function switchToPlayerWithConfirmation(currentPlayerId,id,target,currentDeviceName){var options;-1!==_playbackmanager.default.getSupportedCommands().indexOf("EndSession")&&id!==currentPlayerId?((currentPlayerId=[]).push({name:_globalize.default.translate("Yes"),id:"yes"}),currentPlayerId.push({name:_globalize.default.translate("No"),id:"no"}),options={buttons:currentPlayerId,text:_globalize.default.translate("ConfirmEndPlayerSession",currentDeviceName)},Emby.importModule("./modules/dialog/dialog.js").then(function(dialog){return dialog(options)}).then(function(dialogResult){switch(dialogResult){case"yes":_playbackmanager.default.getCurrentPlayer().endSession(),switchToPlayer(id,target);break;case"no":switchToPlayer(id,target)}},emptyCallback)):switchToPlayer(id,target)}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 _currentPlayerInfo,currentPlayerInfo=_playbackmanager.default.getPlayerInfo(),currentPlayerId=null==(_currentPlayerInfo=currentPlayerInfo)?void 0:_currentPlayerInfo.id;return _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:getIcon(t.deviceType)}}),menuItems=(menuItems.unshift({name:_servicelocator.appHost.deviceName(),nameSubtitle:_servicelocator.appHost.appName(),id:LocalPlayerId,selected:!currentPlayerInfo||currentPlayerInfo.isLocalPlayer,icon:_browser.default.tv||_layoutmanager.default.tv?getIcon("tv"):"ontouchstart"in document?getIcon("smartphone"):getIcon("desktop")}),_loading.default.hide(),{title:_globalize.default.translate("HeaderPlayOn"),items:menuItems,positionTo:button,positionY:"bottom",positionX:"right",transformOrigin:"right top",resolveOnClick:!0,hasItemIcon:!0,fields:["Name","NameSubtitle","ShortOverview"],hasItemSelectionState:!0});return _servicelocator.appHost.supports("castmenuhashchange")&&!function(){for(var _navigator$userAgentD,brands=(null==(_navigator$userAgentD=navigator.userAgentData)?void 0:_navigator$userAgentD.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){currentPlayerInfo=_playbackmanager.default.getPlayerInfo(),currentPlayerId=null==(_currentPlayerInfo2=currentPlayerInfo)?void 0:_currentPlayerInfo2.id;var _currentPlayerInfo2=targets.filter(function(t){return t.id===id})[0],_currentPlayerInfo3=(null==(_currentPlayerInfo3=currentPlayerInfo)?void 0:_currentPlayerInfo3.deviceName)||(null==(_currentPlayerInfo3=currentPlayerInfo)?void 0:_currentPlayerInfo3.name);switchToPlayerWithConfirmation(currentPlayerId,id,_currentPlayerInfo2,_currentPlayerInfo3)},emptyCallback)})}}});