import*as SDK from"../sdk/sdk.js";import*as LitHtml from"../third_party/lit-html/lit-html.js";import*as UIComponents from"../ui/components/components.js";import*as UI from"../ui/ui.js";export class CSPViolationsListView extends UI.Widget.VBox{constructor(){super(!0),this.table=new UIComponents.DataGridController.DataGridController,this.categoryFilter=new Set,this.issueRows=new Map,this.registerRequiredCSS("issues/cspViolationsListView.css",{enableLegacyPatching:!1}),this.table.data={columns:[{id:"sourceCode",title:"Source Code",sortable:!1,widthWeighting:1,visible:!0,hideable:!1},{id:"violatedDirective",title:"Violated Directive",sortable:!1,widthWeighting:1,visible:!0,hideable:!1},{id:"category",title:"Category",sortable:!1,widthWeighting:1,visible:!0,hideable:!1},{id:"status",title:"Status",sortable:!1,widthWeighting:1,visible:!0,hideable:!1}],rows:[]},this.contentElement.appendChild(this.table)}updateTextFilter(t){0===t.length?this.table.data={...this.table.data,filters:[]}:this.table.data={...this.table.data,filters:[{text:t,key:void 0,regex:void 0,negative:!1}]}}updateCategoryFilter(t){this.categoryFilter=t;const e=[];for(const[i,s]of this.issueRows.entries())this.isIssueInFilterCategories(i)&&e.push(s);this.table.data={...this.table.data,rows:e}}isIssueInFilterCategories(t){return this.categoryFilter.has(t.code())||0===this.categoryFilter.size}addIssue(t){const e=t.details().sourceCodeLocation;if(!e)return;const i=t.details().isReportOnly?"report-only":"blocked",s=this.issueViolationCodeToCategoryName(t.code()),o={cells:[{columnId:"sourceCode",value:e.url,renderer:()=>LitHtml.html`<devtools-linkifier .data=${{url:e.url,lineNumber:e.lineNumber}}></devtools-linkifier>`},{columnId:"violatedDirective",value:t.details().violatedDirective},{columnId:"category",value:s},{columnId:"status",value:i}]};this.issueRows.set(t,o),this.isIssueInFilterCategories(t)&&(this.table.data.rows.push(o),this.table.data={...this.table.data})}clearIssues(){this.issueRows.clear(),this.table.data={...this.table.data,rows:[]}}issueViolationCodeToCategoryName(t){return t===SDK.ContentSecurityPolicyIssue.inlineViolationCode?"Inline Violation":t===SDK.ContentSecurityPolicyIssue.urlViolationCode?"URL Violation":t===SDK.ContentSecurityPolicyIssue.evalViolationCode?"Eval Violation":t===SDK.ContentSecurityPolicyIssue.trustedTypesSinkViolationCode?"Sink Violation":t===SDK.ContentSecurityPolicyIssue.trustedTypesPolicyViolationCode?"Policy Violation":"unknown"}}