define(["./emby-apiclient/events.js","./emby-apiclient/connectionmanager.js","./common/usersettings/usersettings.js","./common/playback/playbackmanager.js"],function(_events,_connectionmanager,_usersettings,_playbackmanager){var currentOwnerId,currentPlayer;function playThemeMedia(items,ownerId){items.length?!currentOwnerId&&_playbackmanager.default.isPlaying()||_playbackmanager.default.play({items:items,fullscreen:!1,enableRemotePlayers:!1}).then(function(){currentOwnerId=ownerId}):stopIfPlaying()}function stopIfPlaying(){currentOwnerId&&_playbackmanager.default.stop(),currentOwnerId=null}var excludeTypes=["CollectionFolder","UserView","Program","SeriesTimer","Timer","Person","TvChannel","Channel","User","Plugin","Device","Tag","Genre","GameGenre","MusicGenre","Studio","Log"];document.addEventListener("viewshow",function(e){var _e$detail$params;"true"===(null==(_e$detail$params=e.detail.params)?void 0:_e$detail$params.asDialog)||currentPlayer&&!currentPlayer.isLocalPlayer||e.detail.supportsThemeMedia||playThemeMedia([],null)},!0),document.addEventListener("itemshow",function(e){currentPlayer&&!currentPlayer.isLocalPlayer||(e=e.detail.item)&&e.ServerId&&function(item){var apiClient,enableThemeVideos;!item.CollectionType&&!excludeTypes.includes(item.Type)&&item.ServerId&&item.Id?(apiClient=_connectionmanager.default.getApiClient(item),enableThemeVideos=_usersettings.default.enableThemeVideos(),apiClient.getThemeMedia(item.Id,{UserId:apiClient.getCurrentUserId(),InheritFromParent:!0,EnableThemeSongs:_usersettings.default.enableThemeSongs(),EnableThemeVideos:enableThemeVideos}).then(function(themeMediaResult){var themeMediaResult=themeMediaResult.ThemeVideosResult.Items.length?themeMediaResult.ThemeVideosResult:themeMediaResult.ThemeSongsResult,ownerId=themeMediaResult.OwnerId;ownerId!==currentOwnerId&&playThemeMedia(themeMediaResult.Items,ownerId)})):stopIfPlaying()}(e)},!0),document.addEventListener("itemclear",function(e){currentPlayer&&!currentPlayer.isLocalPlayer||playThemeMedia([],null)},!0),_events.default.on(_playbackmanager.default,"playerchange",function(e,player){currentPlayer=player}),_events.default.on(_playbackmanager.default,"playqueuestart",function(e,player,state){state.IsBackgroundPlayback||(currentOwnerId=null)})});