/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["../../../../../../chunks/_rollupPluginBabelHelpers","../../../../../../core/Logger","../../../../../../symbols/cim/cimAnalyzer","../../../../../../symbols/cim/utils","./WGLMeshTemplate"],(function(e,t,a,n,i){"use strict";const r=t.getLogger("esri.views.2d.engine.webgl.WGLDynamicMeshTemplate");return function(t){function i(e){var a;return(a=t.call(this)||this)._ongoingMaterialRequestMap=new Map,a._materialCache=new Map,a._dynamicPropertyMap=new Map,a._cimLayer=e,a}return e._inheritsLoose(i,t),i.prototype.analyze=function(e,t,i,s,l){if(l&&0===l.length)return null;const o=l&&l.length>0,c=t.readLegacyFeature(),u=t.getObjectId(),m=this._materialCache,h=this._cimLayer.materialHash;if(!h)return r.error("A Dynamic mesh template must have a material hash value or function!"),Promise.reject(null);const g="function"==typeof h?h(c,i,s,u):h;if(m.has(g)){const e=m.get(g);return Promise.resolve(e)}const p=this._ongoingMaterialRequestMap.get(g);if(p)return p;const y=this._cimLayer,M=a.analyzeCIMResource(y.cim,this._cimLayer.materialOverrides);M.mosaicHash=g;const{type:d,url:f}=y,_={cim:M,type:d,mosaicHash:g,url:f,size:null,dashTemplate:null,text:null,fontName:null,objectId:u,animatedSymbolProperties:null};switch(d){case"marker":_.size=n.evaluateValueOrFunction(y.size,c,i,s),_.animatedSymbolProperties=n.evaluateValueOrFunction(y.animatedSymbolProperties,c,i,s);break;case"line":_.dashTemplate=y.dashTemplate;break;case"text":_.text=n.evaluateValueOrFunction(y.text,c,i,s),_.fontName=n.evaluateValueOrFunction(y.fontName,c,i,s)}const b=e.getMosaicItem(_,l).then((e=>(o||(this._ongoingMaterialRequestMap.delete(g),m.set(g,e)),e))).catch((e=>(this._ongoingMaterialRequestMap.delete(g),r.error(".analyze()",e.message),null)));return o||this._ongoingMaterialRequestMap.set(g,b),b},i}(i)}));
