/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["require","exports","../../../../chunks/_rollupPluginBabelHelpers","../../../../core/has","../../../../core/maybe","../../../../core/accessorSupport/diffUtils","../../../../support/arcadeOnDemand","../../arcade/callExpressionWithCursor"],(function(e,t,s,r,i,n,a,o){"use strict";const c=new Promise(((t,s)=>e(["../../../../layers/support/labelFormatUtils"],t,s)));let u=function(){function e(e,t){this._canCacheExpressionValue=!1,this._sourceInfo=e,this._storage=t,this._bitsets={computed:t.getBitset(t.createBitset())}}var t=e.prototype;return t.invalidate=function(){this._bitsets.computed.clear()},t.updateSchema=function(){var e=s._asyncToGenerator((function*(e,t){const s=n.diff(this._schema,t);if(this._schema=t,!t||i.isNone(s)||!n.hasDiff(s,"attributes"))return;r("esri-2d-update-debug")&&console.debug("Applying Update - Store:",s),this._bitsets.computed.clear(),e.targets[t.name]=!0;const a=t.attributes,o=[],c=[];for(const r in a){const e=a[r];switch(e.type){case"field":break;case"expression":o.push(this._createArcadeComputedField(e));break;case"label-expression":o.push(this._createLabelArcadeComputedField(e));break;case"statistic":c.push(e)}}this._computedFields=yield Promise.all(o),this._canCacheExpressionValue=!this._computedFields.some((e=>"expression"===e.type&&e.expression.referencesScale())),this._statisticFields=c}));function t(t,s){return e.apply(this,arguments)}return t}(),t.setComputedAttributes=function(e,t,s,r){const i=this._bitsets.computed;if(!this._canCacheExpressionValue||!i.has(s)){i.set(s);for(const i of this._computedFields){const n=this._evaluateField(t,i,r);switch(i.resultType){case"numeric":e.setComputedNumericAtIndex(s,i.fieldIndex,n);break;case"string":e.setComputedStringAtIndex(s,i.fieldIndex,n)}}}},t._createArcadeComputedField=function(){var e=s._asyncToGenerator((function*(e){const t=this._sourceInfo.spatialReference,s=this._sourceInfo.fieldsIndex;return{...e,expression:yield a.createRendererExpression(e.valueExpression,t,s)}}));function t(t){return e.apply(this,arguments)}return t}(),t._createLabelArcadeComputedField=function(){var e=s._asyncToGenerator((function*(e){const t=this._sourceInfo.spatialReference,s=this._sourceInfo.fieldsIndex,{createLabelFunction:r}=yield c,i=yield r(e.label,s,t);return{...e,builder:i}}));function t(t){return e.apply(this,arguments)}return t}(),t._evaluateField=function(e,t,s){switch(t.type){case"label-expression":{const s=e.readArcadeFeature();return t.builder.evaluate(s)||""}case"expression":{const{expression:r}=t;return o(r,e,{$view:{scale:s}})}}},s._createClass(e,[{key:"storage",get:function(){return this._storage}}]),e}();t.Store2D=u,Object.defineProperties(t,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
