import*as Host from"../host/host.js";import*as i18n from"../i18n/i18n.js";import*as UI from"../ui/ui.js";import{AccessibilitySubPane}from"./AccessibilitySubPane.js";const UIStrings={sourceOrderViewer:"Source Order Viewer",noSourceOrderInformation:"No source order information available",thereMayBeADelayInDisplaying:"There may be a delay in displaying source order for elements with many children",showSourceOrder:"Show source order"},str_=i18n.i18n.registerUIStrings("accessibility/SourceOrderView.ts",UIStrings),i18nString=i18n.i18n.getLocalizedString.bind(void 0,str_),MAX_CHILD_ELEMENTS_THRESHOLD=300;export class SourceOrderPane extends AccessibilitySubPane{constructor(){super(i18nString(UIStrings.sourceOrderViewer)),this._noNodeInfo=this.createInfo(i18nString(UIStrings.noSourceOrderInformation)),this._warning=this.createInfo(i18nString(UIStrings.thereMayBeADelayInDisplaying)),this._warning.id="source-order-warning",this._checked=!1,this._checkboxLabel=UI.UIUtils.CheckboxLabel.create(i18nString(UIStrings.showSourceOrder),!1),this._checkboxElement=this._checkboxLabel.checkboxElement,this._checkboxLabel.classList.add("source-order-checkbox"),this._checkboxElement.addEventListener("click",this._checkboxClicked.bind(this),!1),this.element.appendChild(this._checkboxLabel),this._node=null,this._overlayModel=null}async setNodeAsync(e){if(this._checkboxLabel.classList.contains("hidden")||(this._checked=this._checkboxElement.checked),this._checkboxElement.checked=!1,this._checkboxClicked(),super.setNode(e),!this._node)return void(this._overlayModel=null);let i=!1;const t=this._node.childNodeCount();if(t>0){this._node.children()||await this._node.getSubtree(1,!1);i=this._node.children().some((e=>e.nodeType()===Node.ELEMENT_NODE))}this._noNodeInfo.classList.toggle("hidden",i),this._warning.classList.toggle("hidden",t<300),this._checkboxLabel.classList.toggle("hidden",!i),i?(this._overlayModel=this._node.domModel().overlayModel(),this._checkboxElement.checked=this._checked,this._checkboxClicked()):this._overlayModel=null}_checkboxClicked(){this._node&&this._overlayModel&&(this._checkboxElement.checked?(Host.userMetrics.actionTaken(Host.UserMetrics.Action.SourceOrderViewActivated),this._overlayModel.highlightSourceOrderInOverlay(this._node)):this._overlayModel.hideSourceOrderInOverlay())}}