/* COPYRIGHT Esri - https://js.arcgis.com/5.1.0/LICENSE.txt */
import{getMetersPerUnit as t,supportsUnit as e}from"../../../../symbols/support/unitConversionUtils.js";import{execute as n,clone as s,setContextFeature as i,createFeature as r}from"./featureExpressionInfoUtils.js";class o{constructor(){this._meterUnitOffset=0,this._renderUnitOffset=0,this._unit="meters",this._metersPerElevationInfoUnit=1,this._featureExpressionInfoContext=null,this.mode=null,this.centerInElevationSR=null}get featureExpressionInfoContext(){return this._featureExpressionInfoContext}get meterUnitOffset(){return this._meterUnitOffset}get unit(){return this._unit}set unit(e){this._unit=e,this._metersPerElevationInfoUnit=t(e)}get requiresSampledElevationInfo(){return"absolute-height"!==this.mode}reset(){this.mode=null,this._meterUnitOffset=0,this._renderUnitOffset=0,this._featureExpressionInfoContext=null,this.unit="meters"}set offsetMeters(t){this._meterUnitOffset=t,this._renderUnitOffset=0}set offsetElevationInfoUnits(t){this._meterUnitOffset=t*this._metersPerElevationInfoUnit,this._renderUnitOffset=0}addOffsetRenderUnits(t){this._renderUnitOffset+=t}geometryZWithOffset(t,e){const n=this.calculateOffsetRenderUnits(e);return null!=this.featureExpressionInfoContext?n:t+n}calculateOffsetRenderUnits(t){let e=this._meterUnitOffset;const s=this.featureExpressionInfoContext;return null!=s&&(e+=n(s)*this._metersPerElevationInfoUnit),e/t.unitInMeters+this._renderUnitOffset}setFromElevationInfo(t){this.mode=t.mode,this.unit=e(t.unit)?t.unit:"meters",this.offsetElevationInfoUnits=t.offset??0}setFeatureExpressionInfoContext(t){this._featureExpressionInfoContext=t}updateFeatureExpressionInfoContextForGraphic(t,e,n){t.arcade?(this._featureExpressionInfoContext=s(t),this.updateFeatureExpressionFeature(e,n)):this._featureExpressionInfoContext=t}updateFeatureExpressionFeature(t,e){const n=this.featureExpressionInfoContext;n?.arcade&&(n.cachedResult=void 0,i(this._featureExpressionInfoContext,t.geometry?r(n.arcade.modules,t,e):null))}static fromElevationInfo(t){const e=new o;return null!=t&&e.setFromElevationInfo(t),e}}export{o as ElevationContext};
