import*as Bindings from"../bindings/bindings.js";import*as i18n from"../i18n/i18n.js";import*as UI from"../ui/ui.js";import{Linkifier}from"./Linkifier.js";const UIStrings={removeFromIgnore:"Remove from ignore list",addToIgnore:"Add script to ignore list",showMoreFrame:"Show 1 more frame",showSMoreFrames:"Show {PH1} more frames",unknownSource:"unknown"},str_=i18n.i18n.registerUIStrings("components/JSPresentationUtils.js",UIStrings),i18nString=i18n.i18n.getLocalizedString.bind(void 0,str_);export function buildStackTracePreviewContents(e,n,t={stackTrace:void 0,contentUpdated:void 0,tabStops:void 0}){const{stackTrace:i,contentUpdated:o,tabStops:r}=t,s=document.createElement("span");s.classList.add("monospace"),s.style.display="inline-block";const a=UI.Utils.createShadowRootWithCoreStyles(s,{cssFile:"components/jsUtils.css",enableLegacyPatching:!1,delegatesFocus:void 0}).createChild("table","stack-preview-container");let c=0,d=0;const l=[];function g(t){let i=0;for(const o of t.callFrames){d++;let s=d>30&&t.callFrames.length>31;const c=document.createElement("tr");c.createChild("td").textContent="\n",c.createChild("td","function-name").textContent=UI.UIUtils.beautifyFunctionName(o.functionName);const g=n.maybeLinkifyConsoleCallFrame(e,o,{tabStop:Boolean(r),className:void 0,columnNumber:void 0});if(g){g.addEventListener("contextmenu",u.bind(null,g));const e=Linkifier.uiLocation(g);e&&Bindings.IgnoreListManager.IgnoreListManager.instance().isIgnoreListedUISourceCode(e.uiSourceCode)&&(s=!0),c.createChild("td").textContent=" @ ",c.createChild("td").appendChild(g),g.textContent&&"\u200b"!==g.textContent||(g.textContent=i18nString(UIStrings.unknownSource)),l.push(g)}s&&(c.classList.add("ignore-listed"),++i),a.appendChild(c)}return c+=i,t.callFrames.length===i}function u(e,n){const t=new UI.ContextMenu.ContextMenu(n);n.consume(!0);const i=Linkifier.uiLocation(e);i&&Bindings.IgnoreListManager.IgnoreListManager.instance().canIgnoreListUISourceCode(i.uiSourceCode)&&(Bindings.IgnoreListManager.IgnoreListManager.instance().isIgnoreListedUISourceCode(i.uiSourceCode)?t.debugSection().appendItem(i18nString(UIStrings.removeFromIgnore),(()=>Bindings.IgnoreListManager.IgnoreListManager.instance().unIgnoreListUISourceCode(i.uiSourceCode))):t.debugSection().appendItem(i18nString(UIStrings.addToIgnore),(()=>Bindings.IgnoreListManager.IgnoreListManager.instance().ignoreListUISourceCode(i.uiSourceCode)))),t.appendApplicableItems(n),t.show()}if(!i)return{element:s,links:l};g(i);let m=i.parent;for(;m;){if(!m.callFrames.length){m=m.parent;continue}const e=a.createChild("tr");e.createChild("td").textContent="\n",e.createChild("td","stack-preview-async-description").textContent=UI.UIUtils.asyncStackTraceLabel(m.description),e.createChild("td"),e.createChild("td"),g(m)&&e.classList.add("ignore-listed"),m=m.parent}if(c){const e=a.createChild("tr","show-ignore-listed-link");e.createChild("td").textContent="\n";const n=e.createChild("td");n.colSpan=4;const t=n.createChild("span","link");t.textContent=1===c?i18nString(UIStrings.showMoreFrame):i18nString(UIStrings.showSMoreFrames,{PH1:c}),t.addEventListener("click",(()=>{a.classList.add("show-ignore-listed"),o&&o()}),!1)}return{element:s,links:l}}export let Options;