import*as BrowserSDK from"../browser_sdk/browser_sdk.js";import*as i18n from"../i18n/i18n.js";import*as SDK from"../sdk/sdk.js";import*as UI from"../ui/ui.js";import{ComboBoxOfCheckBoxes}from"./ComboBoxOfCheckBoxes.js";import{CSPViolationsListView}from"./CSPViolationsListView.js";const UIStrings={filter:"Filter"},str_=i18n.i18n.registerUIStrings("issues/CSPViolationsView.ts",UIStrings),i18nString=i18n.i18n.getLocalizedString.bind(void 0,str_);let cspViolationsViewInstance;export class CSPViolationsView extends UI.Widget.VBox{constructor(){super(!0),this.listView=new CSPViolationsListView,this.issuesManager=BrowserSDK.IssuesManager.IssuesManager.instance(),this.registerRequiredCSS("issues/cspViolationsView.css",{enableLegacyPatching:!1}),this.contentElement.classList.add("csp-violations-pane");const e=new UI.Toolbar.Toolbar("csp-violations-toolbar",this.contentElement),s=new UI.Toolbar.ToolbarInput(i18nString(UIStrings.filter),"",1,.2,"");s.addEventListener(UI.Toolbar.ToolbarInput.Event.TextChanged,(()=>{this.listView.updateTextFilter(s.value())})),e.appendToolbarItem(s);const t=new ComboBoxOfCheckBoxes("Categories");t.setText("Categories"),t.addOption("Trusted Type Policy",SDK.ContentSecurityPolicyIssue.trustedTypesPolicyViolationCode,!0),t.addOption("Trusted Type Sink",SDK.ContentSecurityPolicyIssue.trustedTypesSinkViolationCode,!0),t.addOption("CSP Inline",SDK.ContentSecurityPolicyIssue.inlineViolationCode,!0),t.addOption("CSP Eval",SDK.ContentSecurityPolicyIssue.evalViolationCode,!0),t.addOption("CSP URL",SDK.ContentSecurityPolicyIssue.urlViolationCode,!0),t.addHeader("Reset",(()=>{t.getOptions().forEach(((e,s)=>t.setOptionEnabled(s,e.default)))})),t.setOnOptionClicked((()=>{const e=new Set(t.getOptions().filter((e=>e.enabled)).map((e=>e.value)));this.listView.updateCategoryFilter(e)})),e.appendToolbarItem(t),this.listView.show(this.contentElement),this.issuesManager.addEventListener(BrowserSDK.IssuesManager.Events.IssueAdded,this.onIssueAdded,this),this.issuesManager.addEventListener(BrowserSDK.IssuesManager.Events.FullUpdateRequired,this.onFullUpdateRequired,this),this.addAllIssues()}static instance(e={forceNew:null}){const{forceNew:s}=e;return cspViolationsViewInstance&&!s||(cspViolationsViewInstance=new CSPViolationsView),cspViolationsViewInstance}onIssueAdded(e){const{issue:s}=e.data;s instanceof SDK.ContentSecurityPolicyIssue.ContentSecurityPolicyIssue&&this.listView.addIssue(s)}onFullUpdateRequired(){this.listView.clearIssues(),this.addAllIssues()}addAllIssues(){for(const e of this.issuesManager.issues())e instanceof SDK.ContentSecurityPolicyIssue.ContentSecurityPolicyIssue&&this.listView.addIssue(e)}}