/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.25/esri/copyright.txt for details. */ import t from"./Dictionary.js";import e from"./ImmutableArray.js";import{a as i,b as s,c as r,t as a,f as o,k as n,d as l}from"../chunks/languageUtils.js";import u from"../geometry/Geometry.js";import h from"../geometry/Point.js";import{fromJSON as f}from"../geometry/support/jsonUtils.js";import{convertToGeometry as y}from"../layers/graphics/featureConversionUtils.js";import{isSome as c,unwrap as m}from"../core/maybe.js";import{ArcadeExecutionError as d,ExecutionErrorCodes as _}from"./executionError.js";class g{constructor(){this.arcadeDeclaredClass="esri.arcade.Feature",this._optimizedGeomDefinition=null,this._geometry=null,this.attributes=null,this._layer=null,this._datesfixed=!0,this.immutable=!0,this._datefields=null,this.immutable=!0}static createFromGraphic(t){const e=new g;return e._geometry=c(t.geometry)?t.geometry:null,void 0===t.attributes||null===t.attributes?e.attributes={}:e.attributes=t.attributes,t._sourceLayer?(e._layer=t._sourceLayer,e._datesfixed=!1):t._layer?(e._layer=t._layer,e._datesfixed=!1):t.layer&&"fields"in t.layer?(e._layer=t.layer,e._datesfixed=!1):t.sourceLayer&&"fields"in t.sourceLayer&&(e._layer=t.sourceLayer,e._datesfixed=!1),e}static createFromArcadeFeature(t){const e=new g;return e._datesfixed=t._datesfixed,e.attributes=t.attributes,e._geometry=t._geometry,e._optimizedGeomDefinition=t._optimizedGeomDefinition,t._layer&&(e._layer=t._layer),e}static createFromOptimisedFeature(t,e,i){const s=new g;return s._geometry=t.geometry?{geometry:t.geometry}:null,s._optimizedGeomDefinition=i,s.attributes=t.attributes||{},s._layer=e,s._datesfixed=!1,s}static createFromArcadeDictionary(e){const i=new g;return i.attributes=e.field("attributes"),null!==i.attributes&&i.attributes instanceof t?(i.attributes=i.attributes.attributes,null===i.attributes&&(i.attributes={})):i.attributes={},i._geometry=e.field("geometry"),null!==i._geometry&&(i._geometry instanceof t?i._geometry=g.parseGeometryFromDictionary(i._geometry):i._geometry instanceof u||(i._geometry=null)),i}static createFromGraphicLikeObject(t,e,i=null){const s=new g;return null===e&&(e={}),s.attributes=e,s._geometry=c(t)?t:null,s._layer=i,s._layer&&(s._datesfixed=!1),s}repurposeFromGraphicLikeObject(t,e,i=null){null===e&&(e={}),this.attributes=e,this._geometry=t||null,this._layer=i,this._layer?this._datesfixed=!1:this._datesfixed=!0}castToText(t=!1){let o="";!1===this._datesfixed&&this._fixDates();for(const n in this.attributes){""!==o&&(o+=",");const l=this.attributes[n];null==l?o+=JSON.stringify(n)+":null":i(l)||s(l)||r(l)?o+=JSON.stringify(n)+":"+JSON.stringify(l):l instanceof u?o+=JSON.stringify(n)+":"+a(l):l instanceof e||l instanceof Array?o+=JSON.stringify(n)+":"+a(l,null,t):l instanceof Date?o+=t?JSON.stringify(n)+":"+JSON.stringify(l.getTime()):JSON.stringify(n)+":"+JSON.stringify(l):null!==l&&"object"==typeof l&&void 0!==l.castToText&&(o+=JSON.stringify(n)+":"+l.castToText(t))}return'{"geometry":'+(null===this.geometry()?"null":a(this.geometry()))+',"attributes":{'+o+"}}"}_fixDates(){if(null!==this._datefields)return this._datefields.length>0&&this._fixDateFields(this._datefields),void(this._datesfixed=!0);const t=[],e=this._layer.fields;for(let i=0;i0&&this._fixDateFields(t),this._datesfixed=!0}_fixDateFields(t){this.attributes={...this.attributes};for(let e=0;e