import{ContentSecurityPolicyIssue}from"./ContentSecurityPolicyIssue.js";import{CorsIssue}from"./CorsIssue.js";import{CrossOriginEmbedderPolicyIssue,isCrossOriginEmbedderPolicyIssue}from"./CrossOriginEmbedderPolicyIssue.js";import{HeavyAdIssue}from"./HeavyAdIssue.js";import{LowTextContrastIssue}from"./LowTextContrastIssue.js";import{MixedContentIssue}from"./MixedContentIssue.js";import{SameSiteCookieIssue}from"./SameSiteCookieIssue.js";import{Capability,SDKModel}from"./SDKModel.js";import{SharedArrayBufferIssue}from"./SharedArrayBufferIssue.js";import{TrustedWebActivityIssue}from"./TrustedWebActivityIssue.js";export class IssuesModel extends SDKModel{constructor(e){super(e),this._enabled=!1,this._auditsAgent=null,this.ensureEnabled(),this._disposed=!1}ensureEnabled(){this._enabled||(this._enabled=!0,this.target().registerAuditsDispatcher(this),this._auditsAgent=this.target().auditsAgent(),this._auditsAgent.invoke_enable())}issueAdded(e){const s=this._createIssuesFromProtocolIssue(e.issue);for(const t of s)this.addIssue(t)}addIssue(e){this.dispatchEventToListeners(Events.IssueAdded,{issuesModel:this,issue:e})}_createIssuesFromProtocolIssue(e){const s=issueCodeHandlers.get(e.code);return s?s(this,e.details):(console.warn(`No handler registered for issue code ${e.code}`),[])}dispose(){super.dispose(),this._disposed=!0}getTargetIfNotDisposed(){return this._disposed?null:this.target()}}function createIssuesForSameSiteCookieIssue(e,s){const t=s.sameSiteCookieIssueDetails;return t?SameSiteCookieIssue.createIssuesFromSameSiteDetails(t,e):(console.warn("SameSite issue without details received."),[])}function createIssuesForMixedContentIssue(e,s){const t=s.mixedContentIssueDetails;return t?[new MixedContentIssue(t,e)]:(console.warn("Mixed content issue without details received."),[])}function createIssuesForContentSecurityPolicyIssue(e,s){const t=s.contentSecurityPolicyIssueDetails;return t?[new ContentSecurityPolicyIssue(t,e)]:(console.warn("Content security policy issue without details received."),[])}function createIssuesForHeavyAdIssue(e,s){const t=s.heavyAdIssueDetails;return t?[new HeavyAdIssue(t,e)]:(console.warn("Heavy Ad issue without details received."),[])}function createIssuesForBlockedByResponseIssue(e,s){const t=s.blockedByResponseIssueDetails;return t?isCrossOriginEmbedderPolicyIssue(t.reason)?[new CrossOriginEmbedderPolicyIssue(t,e)]:[]:(console.warn("BlockedByResponse issue without details received."),[])}function createIssuesForSharedArrayBufferIssue(e,s){const t=s.sharedArrayBufferIssueDetails;return t?[new SharedArrayBufferIssue(t,e)]:(console.warn("SAB transfer issue without details received."),[])}function createIssuesForTrustedWebActivityIssue(e,s){const t=s.twaQualityEnforcementDetails;return t?[new TrustedWebActivityIssue(t)]:(console.warn("TWA Quality Enforcement issue without details received."),[])}function createIssuesForLowTextContrastIssue(e,s){const t=s.lowTextContrastIssueDetails;return t?[new LowTextContrastIssue(t)]:(console.warn("LowTextContrast issue without details received."),[])}function createIssuesForCorsIssue(e,s){const t=s.corsIssueDetails;return t?[new CorsIssue(t,e)]:(console.warn("Cors issue without details received."),[])}const issueCodeHandlers=new Map([[Protocol.Audits.InspectorIssueCode.SameSiteCookieIssue,createIssuesForSameSiteCookieIssue],[Protocol.Audits.InspectorIssueCode.MixedContentIssue,createIssuesForMixedContentIssue],[Protocol.Audits.InspectorIssueCode.HeavyAdIssue,createIssuesForHeavyAdIssue],[Protocol.Audits.InspectorIssueCode.ContentSecurityPolicyIssue,createIssuesForContentSecurityPolicyIssue],[Protocol.Audits.InspectorIssueCode.BlockedByResponseIssue,createIssuesForBlockedByResponseIssue],[Protocol.Audits.InspectorIssueCode.SharedArrayBufferIssue,createIssuesForSharedArrayBufferIssue],[Protocol.Audits.InspectorIssueCode.TrustedWebActivityIssue,createIssuesForTrustedWebActivityIssue],[Protocol.Audits.InspectorIssueCode.LowTextContrastIssue,createIssuesForLowTextContrastIssue],[Protocol.Audits.InspectorIssueCode.CorsIssue,createIssuesForCorsIssue]]);export const Events={IssueAdded:Symbol("IssueAdded")};SDKModel.register(IssuesModel,Capability.Audits,!0);