/*
All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
*/
import{numericHash as e}from"../../../../../core/string.js";import{createRendererExpression as t}from"../../../../../support/ArcadeExpression.js";import{callExpressionWithCursor as r,callExpressionWithCursorWithDefault as s}from"../../../arcade/callExpressionWithCursor.js";import{AComputedField as a}from"./AComputedField.js";function c(e,t){const r=43758.5453*Math.sin(12.9898*e+78.233*t);return r-Math.floor(r)}class i extends a{static async create(r,s){const a=await t(r,s.spatialReference),c=e(r);return new i(a,c)}constructor(e,t){super(),this._compiled=e,this._cacheKey=t}resize(e){}read(e,t){return this.hasArcadeDependency("scale")||"system"!==t.$view.timeZone?r(this._compiled,e,t):this._readCached(e,t)}readWithDefault(e,t,r){return this.hasArcadeDependency("scale")||"system"!==t.$view.timeZone?s(this._compiled,e,t,r):this._readWithDefaultCached(e,t,r)}hasArcadeDependency(e){return this._compiled?.references(e)??!1}_getCacheKey(e){if(!this._compiled?.references("timeProperties"))return this._cacheKey;const{currentStart:t,currentEnd:r}=e.$view.timeProperties;return this._cacheKey+c(t??1,r??1)}_readCached(e,t){if(e.setCache(this._getCacheKey(t)),e.hasCachedValue())return e.getCachedValue();const s=r(this._compiled,e,t);return e.setCachedValue(s),s}_readWithDefaultCached(e,t,r){if(e.setCache(this._getCacheKey(t)),e.hasCachedValue())return e.getCachedValue();const a=s(this._compiled,e,t,r);return e.setCachedValue(a),a}}export{i as ComputedExpression};
