import*as d from"./../../core/common/common.js";import*as E from"./../greendev/greendev.js";var s;(function(e){e[e.ELEMENT_NODE=0]="ELEMENT_NODE",e[e.STYLE_RULE=1]="STYLE_RULE",e[e.NETWORK_REQUEST=2]="NETWORK_REQUEST",e[e.NETWORK_REQUEST_SUBPANEL_HEADERS=3]="NETWORK_REQUEST_SUBPANEL_HEADERS"})(s||(s={}));var r=class e{static#e=null;static#i=!1;static#s=!1;#n=new d.ObjectWrapper.ObjectWrapper;#t=[];#o=0;static instance(){return e.#e||(e.#e=new e),e.#e}static annotationsEnabled(){let n=E.Prototypes.instance().isEnabled("aiAnnotations");return n?this.#i&&!this.#s&&(console.warn("Flag controlling GreenDev has flipped from false to true. Only some callers will expect GreenDev to be enabled, which can lead to unexpected results."),this.#s=!0):this.#i=!0,!!n}addEventListener(n,t,o){return e.annotationsEnabled()||console.warn("Received request to add event listener with annotations disabled"),this.#n.addEventListener(n,t,o)}getAnnotationDataByType(n){return e.annotationsEnabled()?this.#t.filter(o=>o.type===n):(console.warn("Received query for annotation types with annotations disabled"),[])}getAnnotationDataById(n){if(!e.annotationsEnabled()){console.warn("Received query for annotation type with annotations disabled");return}return this.#t.find(t=>t.id===n)}#r(n,t){return this.getAnnotationDataByType(n).find(a=>{if(typeof t=="string")return a.lookupId===t;switch(n){case s.ELEMENT_NODE:return a.anchor===t;case s.NETWORK_REQUEST_SUBPANEL_HEADERS:return a.anchor===t;default:return console.warn("[AnnotationRepository] Unknown AnnotationType",n),!1}})}#a(n,t,o){let i=this.#r(t,o);return i?(i.message=n,!0):!1}addElementsAnnotation(n,t,o){if(!e.annotationsEnabled()){console.warn("Received annotation registration with annotations disabled");return}if(this.#a(n,s.ELEMENT_NODE,t))return;let i={id:this.#o++,type:s.ELEMENT_NODE,message:n,lookupId:typeof t=="string"?t:"",anchor:typeof t!="string"?t:void 0,anchorToString:o};this.#t.push(i),console.log("[AnnotationRepository] Added element annotation:",n,{annotationData:i,annotations:this.#t.length}),this.#n.dispatchEventToListeners("AnnotationAdded",i)}addNetworkRequestAnnotation(n,t,o){if(!e.annotationsEnabled()){console.warn("Received annotation registration with annotations disabled");return}if(this.#a(n,s.NETWORK_REQUEST_SUBPANEL_HEADERS,t))return;let i={id:this.#o++,type:s.NETWORK_REQUEST,message:"",lookupId:typeof t=="string"?t:"",anchor:typeof t!="string"?t:void 0,anchorToString:o};this.#t.push(i),console.log("[AnnotationRepository] Added annotation:",n,{annotationData:i,annotations:this.#t.length}),this.#n.dispatchEventToListeners("AnnotationAdded",i);let a={id:this.#o++,type:s.NETWORK_REQUEST_SUBPANEL_HEADERS,message:n,lookupId:typeof t=="string"?t:"",anchor:typeof t!="string"?t:void 0,anchorToString:o};this.#t.push(a),this.#n.dispatchEventToListeners("AnnotationAdded",a)}deleteAllAnnotations(){this.#t=[],this.#n.dispatchEventToListeners("AllAnnotationsDeleted"),console.log("[AnnotationRepository] Deleting all annotations")}deleteAnnotation(n){let t=this.#t.findIndex(o=>o.id===n);if(t===-1){console.warn(`[AnnotationRepository] Could not find annotation with id ${n}`);return}this.#t.splice(t,1),this.#n.dispatchEventToListeners("AnnotationDeleted",{id:n}),console.log(`[AnnotationRepository] Deleted annotation with id ${n}`)}};export{r as AnnotationRepository,s as AnnotationType};
//# sourceMappingURL=annotations.js.map
