import*as EventListeners from"../event_listeners/event_listeners.js";import*as i18n from"../i18n/i18n.js";import*as SDK from"../sdk/sdk.js";import*as UI from"../ui/ui.js";const UIStrings={refreshGlobalListeners:"Refresh global listeners"},str_=i18n.i18n.registerUIStrings("browser_debugger/ObjectEventListenersSidebarPane.ts",UIStrings),i18nString=i18n.i18n.getLocalizedString.bind(void 0,str_);let objectEventListenersSidebarPaneInstance;export class ObjectEventListenersSidebarPane extends UI.Widget.VBox{constructor(){super(),this._refreshButton=new UI.Toolbar.ToolbarButton(i18nString(UIStrings.refreshGlobalListeners),"largeicon-refresh"),this._refreshButton.addEventListener(UI.Toolbar.ToolbarButton.Events.Click,this._refreshClick,this),this._refreshButton.setEnabled(!1),this._eventListenersView=new EventListeners.EventListenersView.EventListenersView(this.update.bind(this),!0),this._eventListenersView.show(this.element),this.setDefaultFocusedChild(this._eventListenersView)}static instance(){return objectEventListenersSidebarPaneInstance||(objectEventListenersSidebarPaneInstance=new ObjectEventListenersSidebarPane),objectEventListenersSidebarPaneInstance}toolbarItems(){return[this._refreshButton]}update(){this._lastRequestedContext&&(this._lastRequestedContext.runtimeModel.releaseObjectGroup(objectGroupName),delete this._lastRequestedContext);const e=UI.Context.Context.instance().flavor(SDK.RuntimeModel.ExecutionContext);if(!e)return this._eventListenersView.reset(),void this._eventListenersView.addEmptyHolderIfNeeded();this._lastRequestedContext=e,Promise.all([this._windowObjectInContext(e)]).then(this._eventListenersView.addObjects.bind(this._eventListenersView))}wasShown(){super.wasShown(),UI.Context.Context.instance().addFlavorChangeListener(SDK.RuntimeModel.ExecutionContext,this.update,this),this._refreshButton.setEnabled(!0),this.update()}willHide(){super.willHide(),UI.Context.Context.instance().removeFlavorChangeListener(SDK.RuntimeModel.ExecutionContext,this.update,this),this._refreshButton.setEnabled(!1)}_windowObjectInContext(e){return e.evaluate({expression:"self",objectGroup:objectGroupName,includeCommandLineAPI:!1,silent:!0,returnByValue:!1,generatePreview:!1,timeout:void 0,throwOnSideEffect:void 0,disableBreaks:void 0,replMode:void 0,allowUnsafeEvalBlockedByCSP:void 0},!1,!1).then((e=>"error"in e||e.exceptionDetails?null:e.object))}_refreshClick(e){e.data.consume(),this.update()}}export const objectGroupName="object-event-listeners-sidebar-pane";