import*as i18n from"../i18n/i18n.js";import*as UI from"../ui/ui.js";const UIStrings={hidePlayer:"Hide player",hideAllOthers:"Hide all others",savePlayerInfo:"Save player info",players:"Players"},str_=i18n.i18n.registerUIStrings("media/PlayerListView.ts",UIStrings),i18nString=i18n.i18n.getLocalizedString.bind(void 0,str_);export class PlayerEntryTreeElement extends UI.TreeOutline.TreeElement{constructor(e,t,i){super(e.playerTitle,!1),this.titleFromUrl=!0,this._playerStatus=e,this._displayContainer=t,this.setLeadingIcons([UI.Icon.Icon.create("smallicon-videoplayer-playing","media-player")]),this.listItemElement.classList.add("player-entry-tree-element"),this.listItemElement.addEventListener("contextmenu",this._rightClickContextMenu.bind(this,i),!1)}onselect(e){return this._displayContainer.renderMainPanel(this._playerStatus.playerID),!0}_rightClickContextMenu(e,t){const i=new UI.ContextMenu.ContextMenu(t);return i.headerSection().appendItem(i18nString(UIStrings.hidePlayer),this._hidePlayer.bind(this,e)),i.headerSection().appendItem(i18nString(UIStrings.hideAllOthers),this._hideOthers.bind(this,e)),i.headerSection().appendItem(i18nString(UIStrings.savePlayerInfo),this._savePlayer.bind(this,e)),i.show(),!0}_hidePlayer(e){this._displayContainer.markPlayerForDeletion(e)}_savePlayer(e){this._displayContainer.exportPlayerData(e)}_hideOthers(e){this._displayContainer.markOtherPlayersForDeletion(e)}}export class PlayerListView extends UI.Widget.VBox{constructor(e){super(!0),this._playerStatuses=new Map,this._mainContainer=e,this._sidebarTree=new UI.TreeOutline.TreeOutlineInShadow,this.contentElement.appendChild(this._sidebarTree.element),this._sidebarTree.registerRequiredCSS("media/playerListView.css",{enableLegacyPatching:!0}),this._playerList=this._addListSection(i18nString(UIStrings.players)),this._playerList.listItemElement.classList.add("player-entry-header")}deletePlayer(e){this._playerList.removeChild(this._playerStatuses.get(e)),this._playerStatuses.delete(e)}_addListSection(e){const t=new UI.TreeOutline.TreeElement(e,!0);return t.listItemElement.classList.add("storage-group-list-item"),t.setCollapsible(!1),t.selectable=!1,this._sidebarTree.appendChild(t),t}addMediaElementItem(e){const t=new PlayerEntryTreeElement({playerTitle:e,playerID:e,exists:!0,playing:!1,titleEdited:!1},this._mainContainer,e);this._playerStatuses.set(e,t),this._playerList.appendChild(t)}setMediaElementPlayerTitle(e,t,i){if(this._playerStatuses.has(e)){const s=this._playerStatuses.get(e);!s||i&&!s.titleFromUrl||(s.title=t,s.titleFromUrl=i)}}setMediaElementPlayerIcon(e,t){if(this._playerStatuses.has(e)){const i=this._playerStatuses.get(e);if(!i)throw new Error("sidebarEntry is expected to not be null");i.setLeadingIcons([UI.Icon.Icon.create("smallicon-videoplayer-"+t,"media-player")])}}onProperty(e,t){if("kFrameTitle"===t.name&&t.value&&this.setMediaElementPlayerTitle(e,t.value,!1),"kFrameUrl"===t.name){const i=t.value.substring(t.value.lastIndexOf("/")+1);this.setMediaElementPlayerTitle(e,i,!0)}}onError(e,t){}onMessage(e,t){}onEvent(e,t){"PLAY"===t.value?this.setMediaElementPlayerIcon(e,"playing"):"PAUSE"===t.value?this.setMediaElementPlayerIcon(e,"paused"):"WEBMEDIAPLAYER_DESTROYED"===t.value&&this.setMediaElementPlayerIcon(e,"destroyed")}}