import{IssuesManager as e}from"../browser_sdk/browser_sdk.js";import{ObjectWrapper as t,EventTarget as s,Revealer as n,Linkifier as i}from"../common/common.js";import{Issue as a,ContentSecurityPolicyIssue as o,NetworkLog as d,FrameManager as r,OverlayModel as c,SDKModel as l,DOMModel as u,MixedContentIssue as h}from"../sdk/sdk.js";import{ViewManager as p,TreeOutline as f,Icon as m,Tooltip as _,UIUtils as g,XLink as C,Widget as v,Toolbar as k}from"../ui/ui.js";import{Linkifier as I}from"../components/components.js";import{Adorner as w}from"../elements/elements.js";import{NetworkPanel as E,NetworkItemView as R}from"../network/network.js";import{Marked as y}from"../marked/marked.js";import{html as L,render as x}from"../third_party/lit-html/lit-html.js";class A extends a.Issue{constructor(e){super(e),this._cookies=new Map,this._requests=new Map,this._representative=null,this._mixedContents=new Map,this._heavyAdIssueDetails=new Map,this._cspIssues=new Set,this._blockedByResponseDetails=new Map,this._aggregatedIssuesCount=0}primaryKey(){throw new Error("This should never be called")}blockedByResponseDetails(){return this._blockedByResponseDetails.values()}cookies(){return Array.from(this._cookies.values()).map(e=>e.cookie)}cookiesWithRequestIndicator(){return this._cookies.values()}heavyAds(){return this._heavyAdIssueDetails.values()}mixedContents(){return this._mixedContents.values()}cspIssues(){return this._cspIssues}requests(){return this._requests.values()}getDescription(){return this._representative?this._representative.getDescription():null}getCategory(){return this._representative?this._representative.getCategory():a.IssueCategory.Other}getAggregatedIssuesCount(){return this._aggregatedIssuesCount}_keyForCookie(e){const{domain:t,path:s,name:n}=e;return`${t};${s};${n}`}addInstance(e){this._aggregatedIssuesCount++,this._representative||(this._representative=e);let t=!1;for(const s of e.requests())t=!0,this._requests.has(s.requestId)||this._requests.set(s.requestId,s);for(const s of e.cookies()){const e=this._keyForCookie(s);this._cookies.has(e)||this._cookies.set(e,{cookie:s,hasRequest:t})}for(const t of e.mixedContents()){const e=JSON.stringify(t);this._mixedContents.set(e,t)}for(const t of e.heavyAds()){const e=JSON.stringify(t);this._heavyAdIssueDetails.set(e,t)}for(const t of e.blockedByResponseDetails()){const e=JSON.stringify(t,["parentFrame","blockedFrame","requestId","frameId","reason","request"]);this._blockedByResponseDetails.set(e,t)}e instanceof o.ContentSecurityPolicyIssue&&this._cspIssues.add(e)}}class T extends t.ObjectWrapper{constructor(t){super(),this._aggregatedIssuesByCode=new Map,this._issuesManager=t,this._issuesManager.addEventListener(e.Events.IssueAdded,this._onIssueAdded,this),this._issuesManager.addEventListener(e.Events.FullUpdateRequired,this._onFullUpdateRequired,this);for(const e of this._issuesManager.issues())this._aggregateIssue(e)}_onIssueAdded(e){const{issue:t}=e.data;this._aggregateIssue(t)}_onFullUpdateRequired(){this._aggregatedIssuesByCode.clear();for(const e of this._issuesManager.issues())this._aggregateIssue(e);this.dispatchEventToListeners(b.FullUpdateRequired)}_aggregateIssue(e){let t=this._aggregatedIssuesByCode.get(e.code());return t||(t=new A(e.code()),this._aggregatedIssuesByCode.set(e.code(),t)),t.addInstance(e),this.dispatchEventToListeners(b.AggregatedIssueUpdated,t),t}aggregatedIssues(){return this._aggregatedIssuesByCode.values()}numberOfAggregatedIssues(){return this._aggregatedIssuesByCode.size}}const b={AggregatedIssueUpdated:Symbol("AggregatedIssueUpdated"),FullUpdateRequired:Symbol("FullUpdateRequired")};var S=Object.freeze({__proto__:null,AggregatedIssue:A,IssueAggregator:T,Events:b});var M=Object.freeze({__proto__:null,IssueRevealer:class{async reveal(e){if(!(e instanceof a.Issue))throw new Error("Internal error: not a issue");await p.ViewManager.instance().showView("issues-pane");const t=p.ViewManager.instance().view("issues-pane");if(t){(await t.widget()).revealByCode(e.code())}}}});const q=L,D=x;class F extends HTMLElement{constructor(){super(...arguments),this.shadow=this.attachShadow({mode:"open"}),this.tokenData=[]}set data(e){this.tokenData=e.tokens,this.update()}update(){this.render()}render(){D(q`
      <style>
      .message {
        line-height: 20px;
        font-size: 14px;
        color: var(--issue-gray);
        margin-bottom: 4px;
        user-select: text;
      }

      .message p {
        margin-bottom: 16px;
        margin-block-start: 2px;
      }

      .message ul {
        list-style-type: none;
        list-style-position: inside;
        padding-inline-start: 0;
      }

      .message li {
        margin-top: 8px;
        display: list-item;
      }

      .message li::before {
        content: "→";
        -webkit-mask-image: none;
        padding-right: 5px;
        position: relative;
        top: -1px;
      }

      .message code {
        color: var(--issue-black);
        font-size: 12px;
        user-select: text;
        cursor: text;
        background: var(--issue-code);
      }
      </style>
      <div class='message'>
        ${this.tokenData.map(V)}
      </div>
    `,this.shadow)}}customElements.define("devtools-markdown-view",F);const N=e=>e.tokens.map(V),B=new Map([["paragraph",e=>q`<p>${N(e)}</p>`],["list",e=>q`<ul>${e.items.map(V)}</ul>`],["list_item",e=>q`<li>${N(e)}</li>`],["text",e=>e.tokens&&e.tokens.length>0?q`${N(e)}`:q`${e.text}`],["codespan",e=>q`<code>${e.text}</code>`],["space",()=>q``]]),V=e=>{const t=B.get(e.type);if(!t)throw new Error(`Markdown token type '${e.type}' not supported.`);return t(e)};HTMLElement;function O(e){return function(e,t){const s=y.lexer(e),n=function(e){if(0===e.length||"heading"!==e[0].type||1!==e[0].depth)return null;return e[0].text}(s);if(!n)throw new Error("Markdown issue descriptions must start with a heading");const i=document.createElement("devtools-markdown-view");return i.data={tokens:s.slice(1)},{title:n,message:()=>i,issueKind:a.IssueKind.BreakingChange,links:t.links}}(function(e){const t=self.Runtime.cachedResources[e];if(!t)throw new Error(`Markdown file ${e} not found. Declare it as a resource in the module.json file`);return t}(e.file),e)}const U=e=>(/[^/]+$/.exec(e)||/[^/]+\/$/.exec(e)||[""])[0];class P extends f.TreeElement{constructor(e,t){super(),this.toggleOnClick=!0,this._parent=e,this._resourceName=t,this._affectedResourcesCountElement=this.createAffectedResourcesCounter(),this._affectedResources=this.createAffectedResources(),this._affectedResourcesCount=0,this._networkListener=null,this._frameListeners=[],this._unresolvedRequestIds=new Set,this._unresolvedFrameIds=new Set}createAffectedResourcesCounter(){const e=document.createElement("div");return e.classList.add("affected-resource-label"),this.listItemElement.appendChild(e),e}createAffectedResources(){const e=new f.TreeElement,t=document.createElement("table");return t.classList.add("affected-resource-list"),e.listItemElement.appendChild(t),this.appendChild(e),t}getResourceName(e){return 1===e?this._resourceName.singular:this._resourceName.plural}updateAffectedResourceCount(e){this._affectedResourcesCount=e,this._affectedResourcesCountElement.textContent=`${e} ${this.getResourceName(e)}`,this.hidden=0===this._affectedResourcesCount,this._parent.updateAffectedResourceVisibility()}isEmpty(){return 0===this._affectedResourcesCount}clear(){this._affectedResources.textContent=""}expandIfOneResource(){1===this._affectedResourcesCount&&this.expand()}_resolveRequestId(e){const t=d.NetworkLog.instance().requestsForId(e);return t.length||(this._unresolvedRequestIds.add(e),this._networkListener||(this._networkListener=d.NetworkLog.instance().addEventListener(d.Events.RequestAdded,this._onRequestAdded,this))),t}_onRequestAdded(e){const t=e.data,n=this._unresolvedRequestIds.delete(t.requestId());0===this._unresolvedRequestIds.size&&this._networkListener&&(s.EventTarget.removeEventListeners([this._networkListener]),this._networkListener=null),n&&this.update()}_resolveFrameId(e){const t=r.FrameManager.instance().getFrame(e);if(!(t&&t.url||(this._unresolvedFrameIds.add(e),this._frameListeners.length))){const e=r.FrameManager.instance().addEventListener(r.Events.FrameAddedToTarget,this._onFrameChanged,this),t=r.FrameManager.instance().addEventListener(r.Events.FrameNavigated,this._onFrameChanged,this);this._frameListeners=[e,t]}return t}_onFrameChanged(e){const t=e.data.frame;if(!t.url)return;const n=this._unresolvedFrameIds.delete(t.id);0===this._unresolvedFrameIds.size&&this._frameListeners.length&&(s.EventTarget.removeEventListeners(this._frameListeners),this._frameListeners=[]),n&&this.update()}_createFrameCell(e){const t=this._resolveFrameId(e),s=t&&(t.unreachableUrl()||t.url)||ls`unknown`,i=document.createElement("td");if(i.classList.add("affected-resource-cell"),t){const t=m.Icon.create("mediumicon-elements-panel","icon");t.classList.add("link"),t.onclick=async()=>{const t=r.FrameManager.instance().getFrame(e);if(t){const e=await t.getOwnerDOMNodeOrDocument();e&&n.reveal(e)}},_.Tooltip.install(t,ls`Click to reveal the frame's DOM node in the Elements panel`),i.appendChild(t)}return i.appendChild(document.createTextNode(s)),i.onmouseenter=()=>{const t=r.FrameManager.instance().getFrame(e);t&&t.highlight()},i.onmouseleave=()=>c.OverlayModel.hideDOMNodeHighlight(),i}_createRequestCell(e){let t=e.url,s=t?U(t):"";const n=document.createElement("td");n.classList.add("affected-resource-cell");const i=m.Icon.create("mediumicon-network-panel","icon");n.appendChild(i);const a=this._resolveRequestId(e.requestId);if(a.length){const e=a[0];n.onclick=()=>{E.NetworkPanel.selectAndShowRequest(e,R.Tabs.Headers)},n.classList.add("link"),i.classList.add("link"),t=e.url(),s=U(t),i.title=ls`Click to show request in the network panel`}else i.title=ls`Request unavailable in the network panel, try reloading the inspected page`,i.classList.add("unavailable");return t&&(n.title=t),n.appendChild(document.createTextNode(s)),n}update(){throw new Error("This should never be called, did you forget to override?")}}class H extends P{constructor(e,t){super(e,{singular:ls`element`,plural:ls`elements`}),this._issue=t}async _appendAffectedElements(e){let t=0;for(const s of e)await this._appendAffectedElement(s),t++;this.updateAffectedResourceCount(t)}async _appendAffectedElement({backendNodeId:e,nodeName:t}){const s=l.TargetManager.instance().mainTarget(),n=new u.DeferredDOMNode(s,e),a=await i.Linkifier.linkify(n);a.textContent=t;const o=document.createElement("td");o.classList.add("affected-resource-element","devtools-link"),o.appendChild(a);const d=document.createElement("tr");d.appendChild(o),this._affectedResources.appendChild(d)}update(){this.clear(),this._appendAffectedElements(this._issue.elements())}}class $ extends P{constructor(e,t){super(e,{singular:ls`directive`,plural:ls`directives`}),this._issue=t}_appendDirectiveColumnTitle(e){const t=document.createElement("td");t.classList.add("affected-resource-header"),t.textContent=ls`Directive`,e.appendChild(t)}_appendURLColumnTitle(e){const t=document.createElement("td");t.classList.add("affected-resource-header"),t.classList.add("affected-resource-directive-info-header"),t.textContent=ls`Resource`,e.appendChild(t)}_appendElementColumnTitle(e){const t=document.createElement("td");t.classList.add("affected-resource-header"),t.textContent=ls`Element`,e.appendChild(t)}_appendSourceCodeColumnTitle(e){const t=document.createElement("td");t.classList.add("affected-resource-header"),t.textContent=ls`Source code`,e.appendChild(t)}_appendStatusColumnTitle(e){const t=document.createElement("td");t.classList.add("affected-resource-header"),t.textContent=ls`Status`,e.appendChild(t)}_appendBlockedStatus(e){const t=document.createElement("td");t.classList.add("affected-resource-blocked-status"),t.textContent=ls`blocked`,e.appendChild(t)}_appendViolatedDirective(e,t){const s=document.createElement("td");s.textContent=t,e.appendChild(s)}_appendBlockedURL(e,t){const s=document.createElement("td");s.classList.add("affected-resource-directive-info"),s.textContent=t,e.appendChild(s)}_appendBlockedElement(e,t,s){const i=document.createElement("td");if(i.classList.add("affected-resource-csp-info-node"),t){const e=t,a=m.Icon.create("largeicon-node-search","icon");a.classList.add("element-reveal-icon"),a.onclick=()=>{const t=s.getTargetIfNotDisposed();if(t){const s=new u.DeferredDOMNode(t,e);n.reveal(s)}},_.Tooltip.install(a,ls`Click to reveal the violating DOM node in the Elements panel`),i.appendChild(a),i.onmouseenter=()=>{const t=s.getTargetIfNotDisposed();if(t){const s=new u.DeferredDOMNode(t,e);s&&s.highlight()}},i.onmouseleave=()=>c.OverlayModel.hideDOMNodeHighlight()}e.appendChild(i)}_appendSourceLocation(e,t){const s=document.createElement("td");if(t){const e=40,n=new I.Linkifier(e).linkifyScriptLocation(null,null,t.url,t.lineNumber);s.appendChild(n)}e.appendChild(s)}_appendAffectedContentSecurityPolicyDetails(e){const t=document.createElement("tr");if(this._issue.code()===o.inlineViolationCode)this._appendDirectiveColumnTitle(t),this._appendElementColumnTitle(t),this._appendSourceCodeColumnTitle(t),this._appendStatusColumnTitle(t);else if(this._issue.code()===o.urlViolationCode)this._appendURLColumnTitle(t),this._appendStatusColumnTitle(t),this._appendDirectiveColumnTitle(t),this._appendSourceCodeColumnTitle(t);else{if(this._issue.code()!==o.evalViolationCode)return void this.updateAffectedResourceCount(0);this._appendSourceCodeColumnTitle(t),this._appendDirectiveColumnTitle(t),this._appendStatusColumnTitle(t)}this._affectedResources.appendChild(t);let s=0;for(const t of e)s++,this._appendAffectedContentSecurityPolicyDetail(t);this.updateAffectedResourceCount(s)}_appendAffectedContentSecurityPolicyDetail(e){const t=document.createElement("tr");t.classList.add("affected-resource-directive");const s=e.details();if(this._issue.code()===o.inlineViolationCode)this._appendViolatedDirective(t,s.violatedDirective),this._appendBlockedElement(t,s.violatingNodeId,e.model()),this._appendSourceLocation(t,s.sourceCodeLocation),this._appendBlockedStatus(t);else if(this._issue.code()===o.urlViolationCode){const e=s.blockedURL?s.blockedURL:"";this._appendBlockedURL(t,e),this._appendBlockedStatus(t),this._appendViolatedDirective(t,s.violatedDirective),this._appendSourceLocation(t,s.sourceCodeLocation)}else{if(this._issue.code()!==o.evalViolationCode)return;this._appendSourceLocation(t,s.sourceCodeLocation),this._appendViolatedDirective(t,s.violatedDirective),this._appendBlockedStatus(t)}this._affectedResources.appendChild(t)}update(){this.clear(),this._appendAffectedContentSecurityPolicyDetails(this._issue.cspIssues())}}class j extends P{constructor(e,t){super(e,{singular:ls`cookie`,plural:ls`cookies`}),this._issue=t}_appendAffectedCookies(e){const t=document.createElement("tr"),s=document.createElement("td");s.classList.add("affected-resource-header"),s.textContent="Name",t.appendChild(s);const n=document.createElement("td");n.classList.add("affected-resource-header"),n.classList.add("affected-resource-cookie-info-header"),n.textContent=ls`Domain`+" & "+ls`Path`,t.appendChild(n),this._affectedResources.appendChild(t);let i=0;for(const t of e)i++,this.appendAffectedCookie(t.cookie,t.hasRequest);this.updateAffectedResourceCount(i)}appendAffectedCookie(e,t){const s=document.createElement("tr");s.classList.add("affected-resource-cookie");const n=document.createElement("td");t?n.appendChild(g.createTextButton(e.name,()=>{E.NetworkPanel.revealAndFilter([{filterType:"cookie-domain",filterValue:e.domain},{filterType:"cookie-name",filterValue:e.name},{filterType:"cookie-path",filterValue:e.path}])},"link-style devtools-link")):n.textContent=e.name;const i=document.createElement("td");i.classList.add("affected-resource-cookie-info"),i.textContent=`${e.domain}${e.path}`,s.appendChild(n),s.appendChild(i),this._affectedResources.appendChild(s)}update(){this.clear(),this._appendAffectedCookies(this._issue.cookiesWithRequestIndicator())}}class z extends P{constructor(e,t){super(e,{singular:ls`request`,plural:ls`requests`}),this._issue=t}_appendAffectedRequests(e){let t=0;for(const s of e)for(const e of this._resolveRequestId(s.requestId))t++,this._appendNetworkRequest(e);this.updateAffectedResourceCount(t)}_appendNetworkRequest(e){const t=e.name().trimMiddle(100),s=document.createElement("td"),n=K.get(this._issue.getCategory())||R.Tabs.Headers;s.appendChild(g.createTextButton(t,()=>{E.NetworkPanel.selectAndShowRequest(e,n)},"link-style devtools-link"));const i=document.createElement("tr");i.classList.add("affected-resource-request"),i.appendChild(s),this._affectedResources.appendChild(i)}update(){this.clear();for(const e of this._issue.blockedByResponseDetails())return void this.updateAffectedResourceCount(0);this._appendAffectedRequests(this._issue.requests())}}class W extends P{constructor(e,t){super(e,{singular:ls`source`,plural:ls`sources`}),this._issue=t}_appendAffectedSources(e){let t=0;for(const s of e)this._appendAffectedSource(s),t++;this.updateAffectedResourceCount(t)}_appendAffectedSource({url:e,lineNumber:t,columnNumber:s}){const n=document.createElement("td"),i={columnNumber:s,lineNumber:t,tabStop:!0},a=I.Linkifier.linkifyURL(e,i);n.appendChild(a);const o=document.createElement("tr");o.classList.add("affected-resource-source"),o.appendChild(n),this._affectedResources.appendChild(o)}update(){this.clear(),this._appendAffectedSources(this._issue.sources())}}const K=new Map([[a.IssueCategory.SameSiteCookie,R.Tabs.Cookies],[a.IssueCategory.CrossOriginEmbedderPolicy,R.Tabs.Headers],[a.IssueCategory.MixedContent,R.Tabs.Headers]]);class J extends P{constructor(e,t){super(e,{singular:ls`resource`,plural:ls`resources`}),this._issue=t}_appendAffectedMixedContents(e){const t=document.createElement("tr"),s=document.createElement("td");s.classList.add("affected-resource-header"),s.textContent=ls`Name`,t.appendChild(s);const n=document.createElement("td");n.classList.add("affected-resource-header"),n.textContent=ls`Restriction Status`,t.appendChild(n),this._affectedResources.appendChild(t);let i=0;for(const t of e)t.request?this._resolveRequestId(t.request.requestId).forEach(e=>{this.appendAffectedMixedContent(t,e),i++}):(this.appendAffectedMixedContent(t),i++);this.updateAffectedResourceCount(i)}appendAffectedMixedContent(e,t=null){const s=document.createElement("tr");s.classList.add("affected-resource-mixed-content");const n=U(e.insecureURL),i=document.createElement("td");if(t){const e=t,s=K.get(this._issue.getCategory())||R.Tabs.Headers;i.appendChild(g.createTextButton(n,()=>{E.NetworkPanel.selectAndShowRequest(e,s)},"link-style devtools-link"))}else i.classList.add("affected-resource-mixed-content-info"),i.textContent=n;_.Tooltip.install(i,e.insecureURL),s.appendChild(i);const a=document.createElement("td");a.classList.add("affected-resource-mixed-content-info"),a.textContent=h.MixedContentIssue.translateStatus(e.resolutionStatus),s.appendChild(a),this._affectedResources.appendChild(s)}update(){this.clear(),this._appendAffectedMixedContents(this._issue.mixedContents())}}class X extends P{constructor(e,t){super(e,{singular:ls`resource`,plural:ls`resources`}),this._issue=t}_appendAffectedHeavyAds(e){const t=document.createElement("tr"),s=document.createElement("td");s.classList.add("affected-resource-header"),s.textContent=ls`Limit exceeded`,t.appendChild(s);const n=document.createElement("td");n.classList.add("affected-resource-header"),n.textContent=ls`Resolution Status`,t.appendChild(n);const i=document.createElement("td");i.classList.add("affected-resource-header"),i.textContent=ls`Frame URL`,t.appendChild(i),this._affectedResources.appendChild(t);let a=0;for(const t of e)this._appendAffectedHeavyAd(t),a++;this.updateAffectedResourceCount(a)}_statusToString(e){switch(e){case Protocol.Audits.HeavyAdResolutionStatus.HeavyAdBlocked:return ls`Removed`;case Protocol.Audits.HeavyAdResolutionStatus.HeavyAdWarning:return ls`Warned`}return""}_limitToString(e){switch(e){case Protocol.Audits.HeavyAdReason.CpuPeakLimit:return ls`CPU peak limit`;case Protocol.Audits.HeavyAdReason.CpuTotalLimit:return ls`CPU total limit`;case Protocol.Audits.HeavyAdReason.NetworkTotalLimit:return ls`Network limit`}return""}_appendAffectedHeavyAd(e){const t=document.createElement("tr");t.classList.add("affected-resource-heavy-ad");const s=document.createElement("td");s.classList.add("affected-resource-heavy-ad-info"),s.textContent=this._limitToString(e.reason),t.appendChild(s);const n=document.createElement("td");n.classList.add("affected-resource-heavy-ad-info"),n.textContent=this._statusToString(e.resolution),t.appendChild(n);const i=e.frame.frameId,a=this._createFrameCell(i);t.appendChild(a),this._affectedResources.appendChild(t)}update(){this.clear(),this._appendAffectedHeavyAds(this._issue.heavyAds())}}class G extends P{constructor(e,t){super(e,{singular:ls`request`,plural:ls`requests`}),this._issue=t}_appendDetails(e){const t=document.createElement("tr"),s=document.createElement("td");s.classList.add("affected-resource-header"),s.textContent=ls`Request`,t.appendChild(s);const n=document.createElement("td");n.classList.add("affected-resource-header"),n.textContent=ls`Parent Frame`,t.appendChild(n);const i=document.createElement("td");i.classList.add("affected-resource-header"),i.textContent=ls`Blocked Resource`,t.appendChild(i),this._affectedResources.appendChild(t);let a=0;for(const t of e)this._appendDetail(t),a++;this.updateAffectedResourceCount(a)}_appendDetail(e){const t=document.createElement("tr");t.classList.add("affected-resource-row");const s=this._createRequestCell(e.request);if(t.appendChild(s),e.parentFrame){const s=this._createFrameCell(e.parentFrame.frameId);t.appendChild(s)}else t.appendChild(document.createElement("td"));if(e.blockedFrame){const s=this._createFrameCell(e.blockedFrame.frameId);t.appendChild(s)}else t.appendChild(document.createElement("td"));this._affectedResources.appendChild(t)}update(){this.clear(),this._appendDetails(this._issue.blockedByResponseDetails())}}class Q extends f.TreeElement{constructor(e,t,s){super(),this._parent=e,this._issue=t,this._description=s,this.toggleOnClick=!0,this.listItemElement.classList.add("issue"),this.childrenListElement.classList.add("body"),this._affectedResources=this._createAffectedResources(),this._affectedResourceViews=[new j(this,this._issue),new H(this,this._issue),new z(this,this._issue),new J(this,this._issue),new W(this,this._issue),new X(this,this._issue),new $(this,this._issue),new G(this,this._issue)],this._aggregatedIssuesCount=null,this._hasBeenExpandedBefore=!1}getIssueTitle(){return this._description.title}onattach(){this._appendHeader(),this._createBody(),this.appendChild(this._affectedResources);for(const e of this._affectedResourceViews)this.appendAffectedResource(e),e.update();this._createReadMoreLinks(),this.updateAffectedResourceVisibility()}appendAffectedResource(e){this._affectedResources.appendChild(e)}_appendHeader(){const e=document.createElement("div");e.classList.add("header");const t=m.Icon.create("largeicon-breaking-change","icon");this._aggregatedIssuesCount=document.createElement("span");const s=w.Adorner.create(this._aggregatedIssuesCount,"countWrapper");s.classList.add("aggregated-issues-count"),this._aggregatedIssuesCount.textContent=""+this._issue.getAggregatedIssuesCount(),e.appendChild(t),e.appendChild(s);const n=document.createElement("div");n.classList.add("title"),n.textContent=this._description.title,e.appendChild(n),this.listItemElement.appendChild(e)}onexpand(){if(!this._hasBeenExpandedBefore){this._hasBeenExpandedBefore=!0;for(const e of this._affectedResourceViews)e.expandIfOneResource()}}_updateAggregatedIssuesCount(){this._aggregatedIssuesCount&&(this._aggregatedIssuesCount.textContent=""+this._issue.getAggregatedIssuesCount())}updateAffectedResourceVisibility(){const e=this._affectedResourceViews.every(e=>e.isEmpty());this._affectedResources.hidden=e}_createAffectedResources(){const e=new f.TreeElement;return e.setCollapsible(!1),e.setExpandable(!0),e.expand(),e.selectable=!1,e.listItemElement.classList.add("affected-resources-label"),e.listItemElement.textContent=ls`Affected Resources`,e.childrenListElement.classList.add("affected-resources"),e}_createBody(){const e=new f.TreeElement;e.setCollapsible(!1),e.selectable=!1;const t=this._description.message();e.listItemElement.appendChild(t),this.appendChild(e)}_createReadMoreLinks(){if(0===this._description.links.length)return;const e=new f.TreeElement;e.setCollapsible(!1),e.listItemElement.classList.add("link-wrapper");const t=e.listItemElement.createChild("ul","link-list");for(const e of this._description.links){const s=C.XLink.create(e.link,ls`Learn more: ${e.linkTitle}`,"link"),n=m.Icon.create("largeicon-link","link-icon");s.prepend(n);t.createChild("li").appendChild(s)}this.appendChild(e)}update(){this._affectedResourceViews.forEach(e=>e.update()),this.updateAffectedResourceVisibility(),this._updateAggregatedIssuesCount()}toggle(e){e||void 0===e&&!this.expanded?this.expand():this.collapse()}}class Y extends v.VBox{constructor(){super(!0),this.registerRequiredCSS("issues/issuesPane.css"),this.contentElement.classList.add("issues-pane"),this._issueViews=new Map;const{toolbarContainer:t,updateToolbarIssuesCount:s}=this._createToolbars();this._issuesToolbarContainer=t,this._updateToolbarIssuesCount=s,this._issuesTree=new f.TreeOutlineInShadow,this._issuesTree.registerRequiredCSS("issues/issuesTree.css"),this._issuesTree.setShowSelectionOnKeyboardFocus(!0),this._issuesTree.contentElement.classList.add("issues"),this.contentElement.appendChild(this._issuesTree.element),this._noIssuesMessageDiv=document.createElement("div"),this._noIssuesMessageDiv.classList.add("issues-pane-no-issues"),this.contentElement.appendChild(this._noIssuesMessageDiv),this._issuesManager=e.IssuesManager.instance(),this._aggregator=new T(this._issuesManager),this._aggregator.addEventListener(b.AggregatedIssueUpdated,this._issueUpdated,this),this._aggregator.addEventListener(b.FullUpdateRequired,this._fullUpdate,this);for(const e of this._aggregator.aggregatedIssues())this._updateIssueView(e);this._issuesManager.addEventListener(e.Events.IssuesCountUpdated,this._updateCounts,this),this._updateCounts()}elementsToRestoreScrollPositionsFor(){return[this._issuesTree.element]}_createToolbars(){const e=this.contentElement.createChild("div","issues-toolbar-container");new k.Toolbar("issues-toolbar-left",e);const t=new k.Toolbar("issues-toolbar-right",e),s=a.getShowThirdPartyIssuesSetting(),n=new k.ToolbarSettingCheckbox(s,ls`Include cookie Issues caused by third-party sites`,ls`Include third-party cookie issues`);t.appendToolbarItem(n),t.appendSeparator();const i=document.createElement("div");i.classList.add("toolbar-warnings");const o=m.Icon.create("largeicon-breaking-change");i.appendChild(o);const d=i.createChild("span","warnings-count-label"),r=new k.ToolbarItem(i);t.appendToolbarItem(r);return{toolbarContainer:e,updateToolbarIssuesCount:e=>{d.textContent=""+e,1===e?r.setTitle(ls`Issues pertaining to ${e} operation detected.`):r.setTitle(ls`Issues pertaining to ${e} operations detected.`)}}}_issueUpdated(e){const t=e.data;this._updateIssueView(t)}_updateIssueView(e){if(!this._issueViews.has(e.code())){let t=e.getDescription();if(!t)return void console.warn("Could not find description for issue code:",e.code());"file"in t&&(t=O(t));const s=new Q(this,e,t);this._issueViews.set(e.code(),s),this._issuesTree.appendChild(s,(e,t)=>e instanceof Q&&t instanceof Q?e.getIssueTitle().localeCompare(t.getIssueTitle()):(console.error("The issues tree should only contain IssueView objects as direct children"),0))}this._issueViews.get(e.code()).update(),this._updateCounts()}_fullUpdate(){for(const e of this._issueViews.values())this._issuesTree.removeChild(e);if(this._issueViews.clear(),this._aggregator)for(const e of this._aggregator.aggregatedIssues())this._updateIssueView(e);this._updateCounts()}_updateCounts(){const e=this._issuesManager.numberOfIssues();this._updateToolbarIssuesCount(e),this._showIssuesTreeOrNoIssuesDetectedMessage(e)}_showIssuesTreeOrNoIssuesDetectedMessage(e){if(e>0)this._issuesTree.element.hidden=!1,this._noIssuesMessageDiv.style.display="none";else{this._issuesTree.element.hidden=!0;const e=this._issuesManager.numberOfAllStoredIssues()>0;this._noIssuesMessageDiv.textContent=e?ls`Only third-party cookie issues detected so far`:ls`No issues detected so far`,this._noIssuesMessageDiv.style.display="flex"}}revealByCode(e){const t=this._issueViews.get(e);t&&(t.expand(),t.reveal())}}var Z=Object.freeze({__proto__:null,IssuesPaneImpl:Y});export{S as IssueAggregator,M as IssueRevealer,Z as IssuesPane};
