import*as Root from"../root/root.js";import*as SDK from"../sdk/sdk.js";import*as UI from"../ui/ui.js";import{AXNodeSubPane}from"./AccessibilityNodeView.js";import{ARIAAttributesPane}from"./ARIAAttributesView.js";import{AXBreadcrumbsPane}from"./AXBreadcrumbsPane.js";import{SourceOrderPane}from"./SourceOrderView.js";let accessibilitySidebarViewInstance;export class AccessibilitySidebarView extends UI.ThrottledWidget.ThrottledWidget{constructor(){super(),this._sourceOrderViewerExperimentEnabled=Root.Runtime.experiments.isEnabled("sourceOrderViewer"),this._node=null,this._axNode=null,this._skipNextPullNode=!1,this._sidebarPaneStack=UI.ViewManager.ViewManager.instance().createStackLocation(),this._breadcrumbsSubPane=new AXBreadcrumbsPane(this),this._sidebarPaneStack.showView(this._breadcrumbsSubPane),this._ariaSubPane=new ARIAAttributesPane,this._sidebarPaneStack.showView(this._ariaSubPane),this._axNodeSubPane=new AXNodeSubPane,this._sidebarPaneStack.showView(this._axNodeSubPane),this._sourceOrderViewerExperimentEnabled&&(this._sourceOrderSubPane=new SourceOrderPane,this._sidebarPaneStack.showView(this._sourceOrderSubPane)),this._sidebarPaneStack.widget().show(this.element),UI.Context.Context.instance().addFlavorChangeListener(SDK.DOMModel.DOMNode,this._pullNode,this),this._pullNode()}static instance(){return accessibilitySidebarViewInstance||(accessibilitySidebarViewInstance=new AccessibilitySidebarView),accessibilitySidebarViewInstance}node(){return this._node}axNode(){return this._axNode}setNode(e,t){this._skipNextPullNode=Boolean(t),this._node=e,this.update()}accessibilityNodeCallback(e){e&&(this._axNode=e,e.isDOMNode()?this._sidebarPaneStack.showView(this._ariaSubPane,this._axNodeSubPane):this._sidebarPaneStack.removeView(this._ariaSubPane),this._axNodeSubPane&&this._axNodeSubPane.setAXNode(e),this._breadcrumbsSubPane&&this._breadcrumbsSubPane.setAXNode(e))}async doUpdate(){const e=this.node();if(this._axNodeSubPane.setNode(e),this._ariaSubPane.setNode(e),this._breadcrumbsSubPane.setNode(e),this._sourceOrderViewerExperimentEnabled&&this._sourceOrderSubPane&&this._sourceOrderSubPane.setNodeAsync(e),!e)return;const t=e.domModel().target().model(SDK.AccessibilityModel.AccessibilityModel);t&&(t.clear(),await t.requestPartialAXTree(e),this.accessibilityNodeCallback(t.axNodeForDOMNode(e)))}wasShown(){super.wasShown(),this.doUpdate(),SDK.SDKModel.TargetManager.instance().addModelListener(SDK.DOMModel.DOMModel,SDK.DOMModel.Events.AttrModified,this._onAttrChange,this),SDK.SDKModel.TargetManager.instance().addModelListener(SDK.DOMModel.DOMModel,SDK.DOMModel.Events.AttrRemoved,this._onAttrChange,this),SDK.SDKModel.TargetManager.instance().addModelListener(SDK.DOMModel.DOMModel,SDK.DOMModel.Events.CharacterDataModified,this._onNodeChange,this),SDK.SDKModel.TargetManager.instance().addModelListener(SDK.DOMModel.DOMModel,SDK.DOMModel.Events.ChildNodeCountUpdated,this._onNodeChange,this)}willHide(){SDK.SDKModel.TargetManager.instance().removeModelListener(SDK.DOMModel.DOMModel,SDK.DOMModel.Events.AttrModified,this._onAttrChange,this),SDK.SDKModel.TargetManager.instance().removeModelListener(SDK.DOMModel.DOMModel,SDK.DOMModel.Events.AttrRemoved,this._onAttrChange,this),SDK.SDKModel.TargetManager.instance().removeModelListener(SDK.DOMModel.DOMModel,SDK.DOMModel.Events.CharacterDataModified,this._onNodeChange,this),SDK.SDKModel.TargetManager.instance().removeModelListener(SDK.DOMModel.DOMModel,SDK.DOMModel.Events.ChildNodeCountUpdated,this._onNodeChange,this)}_pullNode(){this._skipNextPullNode?this._skipNextPullNode=!1:this.setNode(UI.Context.Context.instance().flavor(SDK.DOMModel.DOMNode))}_onAttrChange(e){if(!this.node())return;const t=e.data.node;this.node()===t&&this.update()}_onNodeChange(e){if(!this.node())return;const t=e.data;this.node()===t&&this.update()}}