/*
All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
*/
import has from"../../../../core/has.js";import{NestedMap as e}from"../../../../core/NestedMap.js";import{fromValues as r}from"../../../../core/libs/gl-matrix-2/factories/vec4f64.js";import{BufferViewVec4u8 as t}from"../../../../geometry/support/buffer/BufferView.js";class o{constructor(){this.declaredClass="esri.views.3d.webgl-engine.lib.ObjectAndLayerIdRenderHelper",this.colorZero=new t(new ArrayBuffer(4)),this._layerToOidToColor=new e,this._colorToUID=new Map,this._layerViewUidToGraphicsUidToObjectId=new e,this._layerViewUidToLayerId=new Map,this._layerViewUidToPopupEnabled=new Map}setUidToObjectAndLayerId(e,r,t,o,i,d=null,a=null,s=null){e&&r&&t&&o&&(this._layerViewUidToLayerId.set(o,t),this._layerViewUidToPopupEnabled.set(o,i),i&&this._layerViewUidToGraphicsUidToObjectId.set(o,r,{objectId:e,attributeNodeId:d,attributeIndex:a,subLayerId:s}))}getObjectAndLayerIdColor(e){const t=this.getObjectAndLayerIdColorArray(e);return r(t.get(0,1),t.get(0,2),t.get(0,3),255)}getObjectAndLayerIdColorArray(e){if(!e.layerViewUid||!e.graphicUid)return this.colorZero;const r=this._layerViewUidToPopupEnabled.get(e.layerViewUid);if(void 0===r)return this.colorZero;if(!1===r)return this.colorZero;const o=this._layerViewUidToGraphicsUidToObjectId.get(e.layerViewUid,e.graphicUid)?.objectId;if(!o)return this.colorZero;let i=this._layerToOidToColor.get(e.layerViewUid,o);if(!i){if(!!has("enable-feature:objectAndLayerId-screenshot-testing"))i=o;else for(;!i;){const e=Math.floor(16777214*Math.random())+1;this._colorToUID.has(e)||(i=e)}if(i>16777215)throw new Error("Object ID Overflow");this._layerToOidToColor.set(e.layerViewUid,o,i),this._colorToUID.set(i,e)}const d=new ArrayBuffer(4);new DataView(d).setUint32(0,i,!1);return new t(d)}getColorToObjectAndLayerIdMapping(){const e=new Map;for(const[r,t]of this._colorToUID.entries()){const o=this._layerViewUidToGraphicsUidToObjectId.get(t.layerViewUid,t.graphicUid),i=this._layerViewUidToLayerId.get(t.layerViewUid);o&&i&&e.set(r,o.attributeNodeId?{type:"object-and-layer-and-i3s-id",olid:o.objectId,lid:i,attrId:o.attributeNodeId,attrIdx:o.attributeIndex,subLayerId:o.subLayerId}:{type:"object-and-layer-id",olid:o.objectId,lid:i})}return e}}export{o as ObjectAndLayerIdRenderHelper};
