import*as i18n from"../../../core/i18n/i18n.js";import*as ExpandableList from"../../../ui/components/expandable_list/expandable_list.js";import*as ComponentHelpers from"../../../ui/components/helpers/helpers.js";import*as Components from"../../../ui/legacy/components/utils/utils.js";import*as LitHtml from"../../../ui/lit-html/lit-html.js";import stackTraceRowStyles from"./stackTraceRow.css.js";import stackTraceLinkButtonStyles from"./stackTraceLinkButton.css.js";const UIStrings={cannotRenderStackTrace:"Cannot render stack trace",showSMoreFrames:"{n, plural, =1 {Show # more frame} other {Show # more frames}}",showLess:"Show less"},str_=i18n.i18n.registerUIStrings("panels/application/components/StackTrace.ts",UIStrings),i18nString=i18n.i18n.getLocalizedString.bind(void 0,str_);export class StackTraceRow extends HTMLElement{static litTagName=LitHtml.literal`devtools-stack-trace-row`;#t=this.attachShadow({mode:"open"});#e=null;set data(t){this.#e=t.stackTraceRowItem,this.#a()}connectedCallback(){this.#t.adoptedStyleSheets=[stackTraceRowStyles]}#a(){this.#e&&LitHtml.render(LitHtml.html`
      <div class="stack-trace-row">
              <div class="stack-trace-function-name text-ellipsis" title=${this.#e.functionName}>
                ${this.#e.functionName}
              </div>
              <div class="stack-trace-source-location">
                ${this.#e.link?LitHtml.html`<div class="text-ellipsis">\xA0@\xA0${this.#e.link}</div>`:LitHtml.nothing}
              </div>
            </div>
    `,this.#t,{host:this})}}export class StackTraceLinkButton extends HTMLElement{static litTagName=LitHtml.literal`devtools-stack-trace-link-button`;#t=this.attachShadow({mode:"open"});#s=()=>{};#i=null;#n=!1;set data(t){this.#s=t.onShowAllClick,this.#i=t.hiddenCallFramesCount,this.#n=t.expandedView,this.#a()}connectedCallback(){this.#t.adoptedStyleSheets=[stackTraceLinkButtonStyles]}#a(){if(!this.#i)return;const t=this.#n?i18nString(UIStrings.showLess):i18nString(UIStrings.showSMoreFrames,{n:this.#i});LitHtml.render(LitHtml.html`
      <div class="stack-trace-row">
          <button class="link" @click=${()=>this.#s()}>
            ${t}
          </button>
        </div>
    `,this.#t,{host:this})}}export class StackTrace extends HTMLElement{static litTagName=LitHtml.literal`devtools-resources-stack-trace`;#t=this.attachShadow({mode:"open"});#o=new Components.Linkifier.Linkifier;#r=[];#c=!1;set data(t){const e=t.frame,{creationStackTrace:a,creationStackTraceTarget:s}=e.getCreationStackTraceData();a&&(this.#r=t.buildStackTraceRows(a,s,this.#o,!0,this.#l.bind(this))),this.#a()}#l(t){this.#r=t,this.#a()}#d(){this.#c=!this.#c,this.#a()}createRowTemplates(){const t=[];let e=0;for(const a of this.#r)!this.#c&&a.ignoreListHide||("functionName"in a&&t.push(LitHtml.html`
          <${StackTraceRow.litTagName} data-stack-trace-row .data=${{stackTraceRowItem:a}}></${StackTraceRow.litTagName}>`),"asyncDescription"in a&&t.push(LitHtml.html`
            <div>${a.asyncDescription}</div>
          `)),"functionName"in a&&a.ignoreListHide&&e++;return e&&t.push(LitHtml.html`
      <${StackTraceLinkButton.litTagName} data-stack-trace-row .data=${{onShowAllClick:this.#d.bind(this),hiddenCallFramesCount:e,expandedView:this.#c}}></${StackTraceLinkButton.litTagName}>
      `),t}#a(){if(!this.#r.length)return void LitHtml.render(LitHtml.html`
          <span>${i18nString(UIStrings.cannotRenderStackTrace)}</span>
        `,this.#t,{host:this});const t=this.createRowTemplates();LitHtml.render(LitHtml.html`
        <${ExpandableList.ExpandableList.ExpandableList.litTagName} .data=${{rows:t}}>
        </${ExpandableList.ExpandableList.ExpandableList.litTagName}>
      `,this.#t,{host:this})}}ComponentHelpers.CustomElements.defineComponent("devtools-stack-trace-row",StackTraceRow),ComponentHelpers.CustomElements.defineComponent("devtools-stack-trace-link-button",StackTraceLinkButton),ComponentHelpers.CustomElements.defineComponent("devtools-resources-stack-trace",StackTrace);