/*
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/maybe","../../../../../../core/screenUtils","../../color","../../definitions","../../GeometryUtils","../../number","../../materialKey/MaterialKey","./util","./WGLBaseFillTemplate","./WGLDynamicMeshTemplate","../../util/Result"],(function(t,e,i,s,o,n,a,l,r,c,_,f){"use strict";return function(c){function _(t,_,f){var h,p;if((p=c.call(this,t)||this)._minMaxZoom=a.i1616to32(Math.round(_*o.MIN_MAX_ZOOM_PRECISION_FACTOR),Math.round(f*o.MIN_MAX_ZOOM_PRECISION_FACTOR)),r.isFunction(t.color)){const e=(e,i,o)=>{const n=t.color(e,i,o);return n&&s.premultiplyAlphaRGBA(n)||0};p._dynamicPropertyMap.set("fillColor",e)}else{const e=t.color;p.fillColor=e&&s.premultiplyAlphaRGBA(e)||0}const u="CIMMarkerPlacementInsidePolygon"===(null==(h=t.cim.placement)?void 0:h.type)&&t.cim.placement.shiftOddRows?2:1,y=t.height;if(r.isFunction(y)){const t=(t,e,i)=>y(t,e,i)*u;p._dynamicPropertyMap.set("_height",t)}else p._height=(y||0)*u;const m=t.offsetX;if(r.isFunction(m)){const t=(t,e,s)=>i.pt2px(m(t,e,s));p._dynamicPropertyMap.set("_offsetX",t)}else p._offsetX=i.pt2px(m||0);const d=t.offsetY;if(r.isFunction(d)){const t=(t,e,s)=>i.pt2px(-d(t,e,s));p._dynamicPropertyMap.set("_offsetY",t)}else p._offsetY=i.pt2px(-d||0);const M=t.scaleX;r.isFunction(M)?p._dynamicPropertyMap.set("_scaleX",M):p._scaleX=M||1;const I=t.angle;if(r.isFunction(I)){const t=(t,e,i)=>n.radToByte(I(t,e,i));p._dynamicPropertyMap.set("_angle",t)}else p._angle=n.radToByte(I)||0;if(e.isSome(t.effects)){const e=t.effects;r.isFunction(e)?p._dynamicPropertyMap.set("_effects",e):p._effects=e}return p._cimFillLayer=t,p._bitset=(t.colorLocked?o.BITSET_GENERIC_LOCK_COLOR:0)|(t.applyRandomOffset?o.BITSET_FILL_RANDOM_PATTERN_OFFSET:0)|(t.sampleAlphaOnly?o.BITSET_GENERIC_CONSIDER_ALPHA_ONLY:0),p._fillMaterialKey=l.FillMaterialKey.load(t.materialKey),p}return t._inheritsLoose(_,c),_.fromCIMFill=function(t,e){const[i,s]=r.getMinMaxZoom(t.scaleInfo,e);return new _(t,i,s)},_.prototype.bindFeature=function(t,e,s){const n=t.readLegacyFeature();this._dynamicPropertyMap.forEach(((t,i)=>{this[i]=t(n,e,s)}));const l=this._fillMaterialKey,r=this._materialCache,c=(0,this._cimFillLayer.materialHash)(n,e,s),_=r.get(c);let h=null;if(_&&f.ok(_.spriteMosaicItem)&&(h=_.spriteMosaicItem),h){const{rect:t,width:e,height:s}=h,n=t.x+o.SPRITE_PADDING,r=t.y+o.SPRITE_PADDING,c=n+e,_=r+s;let f=Math.round(i.pt2px(this._height));f<=0&&(f=_-r);let p=Math.round(i.pt2px(this._height/s*e||0));p<=0&&(p=c-n);const u=this._scaleX,y=1;this.tl=a.i1616to32(n,r),this.br=a.i1616to32(c,_),this.aux2_1=a.i1616to32(p,f),this.aux2_2=a.i1616to32(this._offsetX,this._offsetY),this.aux3=a.i8888to32(u,y,this._angle,0),l.sdf=h.sdf,l.pattern=!0,l.textureBinding=h.textureBinding}else this.tl=0,this.br=0,this.aux2_1=0,this.aux2_2=0,this.aux3=0,l.sdf=!1,l.pattern=!1,l.textureBinding=0;this._materialKey=l.data},_}(c(_))}));
