import*as Components from"../components/components.js";import*as i18n from"../i18n/i18n.js";import*as SDK from"../sdk/sdk.js";import*as UI from"../ui/ui.js";const UIStrings={noStackTraceAvailable:"No stack trace available"},str_=i18n.i18n.registerUIStrings("elements/NodeStackTraceWidget.js",UIStrings),i18nString=i18n.i18n.getLocalizedString.bind(void 0,str_);let nodeStackTraceWidgetInstance;export class NodeStackTraceWidget extends UI.ThrottledWidget.ThrottledWidget{constructor(){super(!0),this.registerRequiredCSS("elements/nodeStackTraceWidget.css",{enableLegacyPatching:!1}),this._noStackTraceElement=this.contentElement.createChild("div","gray-info-message"),this._noStackTraceElement.textContent=i18nString(UIStrings.noStackTraceAvailable),this._creationStackTraceElement=this.contentElement.createChild("div","stack-trace"),this._linkifier=new Components.Linkifier.Linkifier(MaxLengthForLinks)}static instance(e={forceNew:null}){const{forceNew:t}=e;return nodeStackTraceWidgetInstance&&!t||(nodeStackTraceWidgetInstance=new NodeStackTraceWidget),nodeStackTraceWidgetInstance}wasShown(){UI.Context.Context.instance().addFlavorChangeListener(SDK.DOMModel.DOMNode,this.update,this),this.update()}willHide(){UI.Context.Context.instance().removeFlavorChangeListener(SDK.DOMModel.DOMNode,this.update,this)}async doUpdate(){const e=UI.Context.Context.instance().flavor(SDK.DOMModel.DOMNode);if(!e)return this._noStackTraceElement.classList.remove("hidden"),void this._creationStackTraceElement.classList.add("hidden");const t=await e.creationStackTrace();if(t){this._noStackTraceElement.classList.add("hidden"),this._creationStackTraceElement.classList.remove("hidden");const n=Components.JSPresentationUtils.buildStackTracePreviewContents(e.domModel().target(),this._linkifier,{stackTrace:t,contentUpdated:void 0,tabStops:void 0});this._creationStackTraceElement.removeChildren(),this._creationStackTraceElement.appendChild(n.element)}else this._noStackTraceElement.classList.remove("hidden"),this._creationStackTraceElement.classList.add("hidden")}}export const MaxLengthForLinks=40;