define(["./emby-apiclient/events.js","./emby-apiclient/connectionmanager.js","./common/appsettings.js","./common/playback/playbackmanager.js"],function(_events,_connectionmanager,_appsettings,_playbackmanager){var currentOwnerId,currentPlayer=_playbackmanager.default.getCurrentPlayer();function playThemeMedia(items,ownerId){items.length?!currentOwnerId&&_playbackmanager.default.isPlaying()||(console.log("thememediaplayer playing theme songs/videos"),_playbackmanager.default.play({items:items,fullscreen:!1,enableRemotePlayers:!1}).then(function(){currentOwnerId=ownerId,_appsettings.default.repeatThemes()&&_playbackmanager.default.setRepeatMode("RepeatAll")})):stopIfPlaying()}function stopIfPlaying(){currentOwnerId&&(console.log("thememediaplayer stop"),_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){var item;currentPlayer&&!currentPlayer.isLocalPlayer||null!=(item=(e=e.detail).item)&&item.ServerId&&function(item,signal){var apiClient,enableThemeVideos;!item.CollectionType&&!excludeTypes.includes(item.Type)&&item.ServerId&&item.Id?(apiClient=_connectionmanager.default.getApiClient(item),enableThemeVideos=_appsettings.default.enableThemeVideos(),apiClient.getThemeMedia(item.Id,{UserId:apiClient.getCurrentUserId(),InheritFromParent:!0,EnableThemeSongs:_appsettings.default.enableThemeSongs(),EnableThemeVideos:enableThemeVideos},signal).then(function(themeMediaResult){var ownerId;null!=signal&&signal.aborted||(ownerId=(themeMediaResult=themeMediaResult.ThemeVideosResult.Items.length?themeMediaResult.ThemeVideosResult:themeMediaResult.ThemeSongsResult).OwnerId)!==currentOwnerId&&playThemeMedia(themeMediaResult.Items,ownerId)})):stopIfPlaying()}(item,e.signal)},!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)})});