/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.24/esri/copyright.txt for details. */ import e from"../arcade/FunctionWrapper.js";import t from"../arcade/ImmutableArray.js";import n from"../arcade/ImmutablePathArray.js";import r from"../arcade/ImmutablePointArray.js";import i from"../geometry/Extent.js";import a from"../geometry/Geometry.js";import o from"../geometry/Multipoint.js";import s from"../geometry/Point.js";import u from"../geometry/Polygon.js";import l from"../geometry/Polyline.js";import{DateTime as f}from"luxon";import{isNone as c}from"../core/maybe.js";import{format as m,parse as d}from"../core/number.js";import{isClockwise as y}from"../geometry/support/coordsUtils.js";import{getLocale as p}from"../intl/locale.js";import{esriFieldToJson as g,layerGeometryEsriRestConstants as h}from"../arcade/featureset/support/shared.js";class S{constructor(e){this.value=e}}class x{constructor(e){this.value=e}}class b{constructor(e){this.fn=e}}class T{constructor(e,t){this.paramCount=t,this.fn=e}}const N=b,k=x,D=S,M=T,j={type:"VOID"},A={type:"BREAK"},R={type:"CONTINUE"};function F(e,t,n){return""===t||null==t||t===n||t===n?e:e=e.split(t).join(n)}function v(t){return t instanceof b||t instanceof e||t instanceof T}function C(e){return!!w(e)||(!!O(e)||(!!z(e)||(!!_(e)||(null===e||(e===j||"number"==typeof e)))))}function I(e,t){return void 0===e?t:e}function w(e){return"string"==typeof e||e instanceof String}function _(e){return"boolean"==typeof e}function O(e){return"number"==typeof e}function Z(e){return"number"==typeof e&&isFinite(e)&&Math.floor(e)===e}function L(e){return e instanceof Array}function Y(e){return"esri.arcade.Feature"===e?.arcadeDeclaredClass}function J(e){return!0===(e&&e.declaredRootClass&&"esri.arcade.featureset.support.FeatureSet"===e.declaredRootClass)}function P(e){return!0===(e&&e.declaredRootClass&&"esri.arcade.featureSetCollection"===e.declaredRootClass)}function E(e){return e instanceof t}function z(e){return e instanceof Date}function G(e,t,n){if(e.lengthn)throw new Error("Function called with wrong number of Parameters")}function V(e){return e<0?-Math.round(-e):Math.round(e)}function H(){let e=Date.now();return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,(function(t){const n=(e+16*Math.random())%16|0;return e=Math.floor(e/16),("x"===t?n:3&n|8).toString(16)}))}function U(e,t){return!1===isNaN(e)?null==t||""===t?e.toString():(t=F(t,"‰",""),t=F(t,"¤",""),m(e,{pattern:t})):e.toString()}function q(e,t){const n=f.fromJSDate(e);return null==t||""===t?n.toISO({suppressMilliseconds:!0}):n.toFormat($(t),{locale:p(),numberingSystem:"latn"})}function $(e){e=e.replace(/LTS|LT|LL?L?L?|l{1,4}/g,"[$&]");let t="";const n=/(\[[^\[]*\])|(\\)?([Hh]mm(ss)?|Mo|MM?M?M?|Do|DDDo|DD?D?D?|ddd?d?|do?|w[o|w]?|W[o|W]?|Qo?|N{1,5}|YYYYYY|YYYYY|YYYY|YY|y{2,4}|yo?|gg(ggg?)?|GG(GGG?)?|e|E|a|A|hh?|HH?|kk?|mm?|ss?|S{1,9}|x|X|zz?|ZZ?|.)/g;for(const r of e.match(n))switch(r){case"D":t+="d";break;case"DD":t+="dd";break;case"DDD":t+="o";break;case"d":t+="c";break;case"ddd":t+="ccc";break;case"dddd":t+="cccc";break;case"M":t+="L";break;case"MM":t+="LL";break;case"MMM":t+="LLL";break;case"MMMM":t+="LLLL";break;case"YY":t+="yy";break;case"Y":case"YYYY":t+="yyyy";break;case"Q":t+="q";break;case"Z":t+="ZZ";break;case"ZZ":t+="ZZZ";break;case"S":t+="'S'";break;case"SS":t+="'SS'";break;case"SSS":t+="u";break;case"A":case"a":t+="a";break;case"m":case"mm":case"h":case"hh":case"H":case"HH":case"s":case"ss":case"X":case"x":t+=r;break;default:r.length>=2&&"["===r.slice(0,1)&&"]"===r.slice(-1)?t+=`'${r.slice(1,-1)}'`:t+=`'${r}'`}return t}function B(e,t,n){switch(n){case">":return e>t;case"<":return e=":return e>=t;case"<=":return e<=t}return!1}function W(e,t,n){if(null===e){if(null===t||t===j)return B(null,null,n);if(O(t))return B(0,t,n);if(w(t))return B(0,ne(t),n);if(_(t))return B(0,ne(t),n);if(z(t))return B(0,t.getTime(),n)}if(e===j){if(null===t||t===j)return B(null,null,n);if(O(t))return B(0,t,n);if(w(t))return B(0,ne(t),n);if(_(t))return B(0,ne(t),n);if(z(t))return B(0,t.getTime(),n)}else if(O(e)){if(O(t))return B(e,t,n);if(_(t))return B(e,ne(t),n);if(null===t||t===j)return B(e,0,n);if(w(t))return B(e,ne(t),n);if(z(t))return B(e,t.getTime(),n)}else if(w(e)){if(w(t))return B(X(e),X(t),n);if(z(t))return B(ne(e),t.getTime(),n);if(O(t))return B(ne(e),t,n);if(null===t||t===j)return B(ne(e),0,n);if(_(t))return B(ne(e),ne(t),n)}else if(z(e)){if(z(t))return B(e,t,n);if(null===t||t===j)return B(e.getTime(),0,n);if(O(t))return B(e.getTime(),t,n);if(_(t))return B(e.getTime(),ne(t),n);if(w(t))return B(e.getTime(),ne(t),n)}else if(_(e)){if(_(t))return B(e,t,n);if(O(t))return B(ne(e),ne(t),n);if(z(t))return B(ne(e),t.getTime(),n);if(null===t||t===j)return B(ne(e),0,n);if(w(t))return B(ne(e),ne(t),n)}return!!Q(e,t)&&("<="===n||">="===n)}function Q(e,t){if(e===t)return!0;if(null===e&&t===j||null===t&&e===j)return!0;if(z(e)&&z(t))return e.getTime()===t.getTime();if(e instanceof n)return e.equalityTest(t);if(e instanceof r)return e.equalityTest(t);if(e instanceof s&&t instanceof s){const n=e.cache._arcadeCacheId,r=t.cache._arcadeCacheId;if(null!=n)return n===r}if(void 0!==e&&void 0!==t&&null!==e&&null!==t&&"object"==typeof e&&"object"==typeof t){if(e._arcadeCacheId===t._arcadeCacheId&&void 0!==e._arcadeCacheId&&null!==e._arcadeCacheId)return!0;if(e._underlyingGraphic===t._underlyingGraphic&&void 0!==e._underlyingGraphic&&null!==e._underlyingGraphic)return!0}return!1}function X(e,n){if(w(e))return e;if(null===e)return"";if(O(e))return U(e,n);if(_(e))return e.toString();if(z(e))return q(e,n);if(e instanceof a)return JSON.stringify(e.toJSON());if(L(e)){const t=[];for(let n=0;ne.key===t.key?0:"spatialReference"===e.key?1:"spatialReference"===t.key||e.keyt.key?1:0));if(L(e)){const t=[];for(let n=0;n0)return e;return null}if(e instanceof l){if(0===e.paths.length)return null;for(const t of e.paths)if(t.length>0)return e;return null}return e instanceof o?0===e.points.length?null:e:e instanceof i?"NaN"===e.xmin||null===e.xmin||isNaN(e.xmin)?null:e:null}function le(e,t){if(!e)return t;if(!e.domain)return t;let n=null;if("string"===e.field.type||"esriFieldTypeString"===e.field.type)t=X(t);else{if(null==t)return null;if(""===t)return t;t=ne(t)}for(let r=0;r0&&(o=e[0].spatialReference,n=e[0].hasZ,i=e[0].hasM)}else if(e instanceof r)a=e._elements,a.length>0&&(n=e._hasZ,i=e._hasM,o=e.get(0).spatialReference);else{if(!E(e))throw new Error("Invalid Argument");for(const t of e.toArray())pe(a,t);a.length>0&&(o=e.get(0).spatialReference,n=!0===e.get(0).hasZ,i=!0===e.get(0).hasM)}if(0===a.length)return null;return!1===y(a,i,n)&&(a=a.slice(0).reverse()),new u({rings:[a],spatialReference:o,hasZ:n,hasM:i})}return e}function he(e,t){if(L(e)||E(e)){let n=!1,i=!1,a=[],o=t;if(L(e)){for(const t of e)pe(a,t);a.length>0&&(o=e[0].spatialReference,n=!0===e[0].hasZ,i=!0===e[0].hasM)}else if(e instanceof r)a=e._elements,a.length>0&&(n=e._hasZ,i=e._hasM,o=e.get(0).spatialReference);else if(E(e)){for(const t of e.toArray())pe(a,t);a.length>0&&(o=e.get(0).spatialReference,n=!0===e.get(0).hasZ,i=!0===e.get(0).hasM)}return 0===a.length?null:new l({paths:[a],spatialReference:o,hasZ:n,hasM:i})}return e}function Se(e,t){if(L(e)||E(e)){let n=!1,i=!1,a=[],s=t;if(L(e)){for(const t of e)pe(a,t);a.length>0&&(s=e[0].spatialReference,n=!0===e[0].hasZ,i=!0===e[0].hasM)}else if(e instanceof r)a=e._elements,a.length>0&&(n=e._hasZ,i=e._hasM,s=e.get(0).spatialReference);else if(E(e)){for(const t of e.toArray())pe(a,t);a.length>0&&(s=e.get(0).spatialReference,n=!0===e.get(0).hasZ,i=!0===e.get(0).hasM)}return 0===a.length?null:new o({points:a,spatialReference:s,hasZ:n,hasM:i})}return e}function xe(e,n=!1){const r=[];if(null===e)return r;if(!0===L(e)){for(let t=0;t{setTimeout((()=>{t(e)}),0)}))):e}function Ne(e,t,n){switch(n){case"&":return e&t;case"|":return e|t;case"^":return e^t;case"<<":return e<>":return e>>t;case">>>":return e>>>t}}function ke(e,n=null){return null==e?null:_(e)||O(e)||w(e)?e:e instanceof a?!0===n?.keepGeometryType?e:e.toJSON():e instanceof t?e.toArray().map((e=>ke(e,n))):e instanceof Array?e.map((e=>ke(e,n))):e instanceof Date?e:null!==e&&"object"==typeof e&&void 0!==e.castAsJson?e.castAsJson(n):null}async function De(e,t,n,r,i){const a=await Me(e,t,n);i[r]=a}async function Me(e,n=null,r=null){if(e instanceof t&&(e=e.toArray()),null==e)return null;if(C(e)||e instanceof a||e instanceof Date)return ke(e,r);if(e instanceof Array){const t=[],i=[];for(const o of e)null===o||C(o)||o instanceof a||o instanceof Date?i.push(ke(o,r)):(i.push(null),t.push(De(o,n,r,i.length-1,i)));return t.length>0&&await Promise.all(t),i}return null!==e&&"object"==typeof e&&void 0!==e.castAsJsonAsync?e.castAsJsonAsync(n,r):null}function je(e,t,n){const r=e.fullSchema();if(null===r)return null;if(!r.fields)return null;return ce(t,r,e,n)}function Ae(e){const t=e.fullSchema();return null===t?null:t.fields&&t.typeIdField?{subtypeField:t.typeIdField,subtypes:t.types?t.types.map((e=>({name:e.name,code:e.id}))):[]}:null}function Re(e,t,n,r){const i=e.fullSchema();if(null===i)return null;if(!i.fields)return null;const a=ce(t,i,e,r);if(void 0===n)try{n=e.field(t)}catch(o){return null}return le(a,n)}function Fe(e,t,n,r){const i=e.fullSchema();if(null===i)return null;if(!i.fields)return null;if(void 0===n){try{n=e.field(t)}catch(a){return null}return n}return fe(ce(t,i,e,r),n)}function ve(e){const t=e.fullSchema();if(null===t)return null;if(!t.fields)return null;const n=[];for(const r of t.fields)n.push(g(r));return{objectIdField:t.objectIdField,globalIdField:t.globalIdField,geometryType:void 0===h[t.geometryType]?"":h[t.geometryType],fields:n}}const Ce=Object.freeze(Object.defineProperty({__proto__:null,ReturnResultE:S,ImplicitResultE:x,NativeFunctionE:b,SizzleFunctionE:T,NativeFunction:N,ImplicitResult:k,ReturnResult:D,SizzleFunction:M,voidOperation:j,breakResult:A,continueResult:R,multiReplace:F,isFunctionParameter:v,isSimpleType:C,defaultUndefined:I,isString:w,isBoolean:_,isNumber:O,isInteger:Z,isArray:L,isFeature:Y,isFeatureSet:J,isFeatureSetCollection:P,isImmutableArray:E,isDate:z,pcCheck:G,absRound:V,generateUUID:H,formatNumber:U,formatDate:q,standardiseDateFormat:$,greaterThanLessThan:W,equalityTest:Q,toString:X,toNumberArray:K,toStringExplicit:ee,toNumber:ne,toDate:re,toDateTime:ie,toBoolean:oe,fixSpatialReference:se,fixNullGeometry:ue,getDomainValue:le,getDomainCode:fe,getDomain:ce,stableStringify:de,autoCastFeatureToGeometry:ye,autoCastArrayOfPointsToPolygon:ge,autoCastArrayOfPointsToPolyline:he,autoCastArrayOfPointsToMultiPoint:Se,toStringArray:xe,tick:Te,binaryOperator:Ne,castAsJson:ke,castAsJsonAsync:Me,featureFullDomain:je,featureSubtypes:Ae,featureDomainValueLookup:Re,featureDomainCodeLookup:Fe,featureSchema:ve},Symbol.toStringTag,{value:"Module"}));export{fe as $,se as A,Z as B,I as C,$ as D,ie as E,V as F,ue as G,ye as H,k as I,he as J,ge as K,Se as L,F as M,N,H as O,ve as P,Ae as Q,D as R,M as S,je as T,Re as U,Fe as V,K as W,Te as X,xe as Y,ce as Z,le as _,O as a,S as a0,x as a1,b as a2,T as a3,U as a4,q as a5,de as a6,w as b,ke as c,Me as d,C as e,ne as f,oe as g,X as h,_ as i,z as j,re as k,L as l,Q as m,E as n,v as o,G as p,W as q,Ne as r,Y as s,ee as t,Ce as u,j as v,A as w,R as x,J as y,P as z};