/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.24/esri/copyright.txt for details. */ import t from"../ArcadePortal.js";import r from"../Attachment.js";import n from"../Dictionary.js";import{p as e,h as o,f as a,O as i,v as u,C as s,g as f,t as c,l,n as d,M as p,s as h,P as y,Q as m,T as g,U as A,V as w,b as I,j as v,i as b,a as j,o as E,y as F,z as P}from"../../chunks/languageUtils.js";import{layerFieldEsriConstants as U}from"../featureset/support/shared.js";import{convertDirection as x}from"./convertdirection.js";import{XXH as C}from"./hash.js";import T from"../../geometry/Extent.js";import N from"../../geometry/Multipoint.js";import k from"../../geometry/Point.js";import L from"../../geometry/Polygon.js";import R from"../../geometry/Polyline.js";import M from"../../geometry/SpatialReference.js";function H(t,r){if(t.x===r.x&&t.y===r.y){if(t.hasZ){if(t.z!==r.z)return!1}else if(r.hasZ)return!1;if(t.hasM){if(t.m!==r.m)return!1}else if(r.hasM)return!1;return!0}return!1}function S(e,o,a){if(null!==e)if(l(e)){if(o.updateUint8Array([61]),a.map.has(e)){const t=a.map.get(e);o.updateIntArray([61237541^t])}else{a.map.set(e,a.currentLength++);for(const t of e)S(t,o,a);a.map.delete(e),a.currentLength--}o.updateUint8Array([199])}else if(d(e)){if(o.updateUint8Array([61]),a.map.has(e)){const t=a.map.get(e);o.updateIntArray([61237541^t])}else{a.map.set(e,a.currentLength++);for(const t of e.toArray())S(t,o,a);a.map.delete(e),a.currentLength--}o.updateUint8Array([199])}else{if(v(e))return o.updateIntArray([e.getTime()]),void o.updateUint8Array([241]);if(I(e))return o.updateIntArray([e.length]),o.updateWithString(e),void o.updateUint8Array([41]);if(b(e))o.updateUint8Array([!0===e?1:0,113]);else{if(j(e))return o.updateFloatArray([e]),void o.updateUint8Array([173]);if(e instanceof r)throw new Error("Type not supported in Hash");if(e instanceof t)throw new Error("Type not supported in Hash");if(!(e instanceof n)){if(h(e))throw new Error("Type not supported in Hash");if(e instanceof k)return o.updateIntArray([3833836621]),o.updateIntArray([0]),o.updateFloatArray([e.x]),o.updateIntArray([1]),o.updateFloatArray([e.y]),e.hasZ&&(o.updateIntArray([2]),o.updateFloatArray([e.z])),e.hasM&&(o.updateIntArray([3]),o.updateFloatArray([e.m])),o.updateIntArray([3765347959]),void S(e.spatialReference.wkid,o,a);if(e instanceof L){o.updateIntArray([1266616829]);for(let t=0;t0)switch(o(n[0]).toLowerCase()){case"digits":return i().replace("-","").replace("-","").replace("-","").replace("-","");case"digits-hyphen":return i();case"digits-hyphen-braces":return"{"+i()+"}";case"digits-hyphen-parentheses":return"("+i()+")"}return"{"+i()+"}"}))},r.console=function(t,r){return v(t,r,(function(r,n,e){return 0===e.length||(1===e.length?t.console(o(e[0])):t.console(o(e))),u}))},r.mid=function(t,r){return v(t,r,(function(t,r,n){e(n,2,3);let i=a(n[1]);if(isNaN(i))return"";if(i<0&&(i=0),2===n.length)return o(n[0]).substr(i);let u=a(n[2]);return isNaN(u)?"":(u<0&&(u=0),o(n[0]).substr(i,u))}))},r.find=function(t,r){return v(t,r,(function(t,r,n){e(n,2,3);let i=0;if(n.length>2){if(i=a(s(n[2],0)),isNaN(i))return-1;i<0&&(i=0)}return o(n[1]).indexOf(o(n[0]),i)}))},r.left=function(t,r){return v(t,r,(function(t,r,n){e(n,2,2);let i=a(n[1]);return isNaN(i)?"":(i<0&&(i=0),o(n[0]).substr(0,i))}))},r.right=function(t,r){return v(t,r,(function(t,r,n){e(n,2,2);let i=a(n[1]);return isNaN(i)?"":(i<0&&(i=0),o(n[0]).substr(-1*i,i))}))},r.split=function(t,r){return v(t,r,(function(t,r,n){let i;e(n,2,4);let u=a(s(n[2],-1));const c=f(s(n[3],!1));if(-1===u||null===u||!0===c?i=o(n[0]).split(o(n[1])):(isNaN(u)&&(u=-1),u<-1&&(u=-1),i=o(n[0]).split(o(n[1]),u)),!1===c)return i;const l=[];for(let e=0;e=u);e++)""!==i[e]&&void 0!==i[e]&&l.push(i[e]);return l}))},r.text=function(t,r){return v(t,r,(function(t,r,n){return e(n,1,2),c(n[0],n[1])}))},r.concatenate=function(t,r){return v(t,r,(function(t,r,n){const e=[];if(n.length<1)return"";if(l(n[0])){const t=s(n[2],"");for(let r=0;r1?e.join(n[1]):e.join("")}if(d(n[0])){const t=s(n[2],"");for(let r=0;r1?e.join(n[1]):e.join("")}for(let o=0;o({name:t.name,code:t.code})))}):n.convertObjectToArcadeDictionary({type:"range",name:t.domain.name,dataType:U[t.field.type],min:t.domain.min,max:t.domain.max}):null}throw new Error("Invalid Parameter")}))},r.domainname=function(t,r){return v(t,r,(function(t,r,n){if(e(n,2,4),h(n[0]))return A(n[0],o(n[1]),n[2],void 0===n[3]?void 0:a(n[3]));throw new Error("Invalid Parameter")}))},r.domaincode=function(t,r){return v(t,r,(function(t,r,n){if(e(n,2,4),h(n[0]))return w(n[0],o(n[1]),n[2],void 0===n[3]?void 0:a(n[3]));throw new Error("Invalid Parameter")}))},r.urlencode=function(t,r){return v(t,r,(function(t,r,a){if(e(a,1,1),null===a[0])return"";if(a[0]instanceof n){let t="";for(const r of a[0].keys()){const n=a[0].field(r);""!==t&&(t+="&"),t+=null===n?encodeURIComponent(r)+"=":encodeURIComponent(r)+"="+encodeURIComponent(n)}return t}return encodeURIComponent(o(a[0]))}))},r.hash=function(t,r){return v(t,r,(function(t,r,n){e(n,1,1);const o=new C(0);return S(n[0],o,{map:new Map,currentLength:0}),o.digest()}))},r.convertdirection=function(t,r){return v(t,r,(function(t,r,n){return e(n,3,3),x(n[0],n[1],n[2])}))},r.fromjson=function(t,r){return v(t,r,(function(t,r,a){if(e(a,1,1),!1===I(a[0]))throw new Error("Invalid Parameter");return n.convertJsonToArcade(JSON.parse(o(a[0])))}))},r.expects=function(t,r){return v(t,r,(function(t,r,n){if(n.length<1)throw new Error("Function called with wrong number of Parameters");return u}))},r.tocharcode=function(t,r){return v(t,r,(function(t,r,n){e(n,1,2);const i=a(s(n[1],0)),u=o(n[0]);if(0===u.length&&1===n.length)return null;if(u.length<=i||i<0)throw new Error("Illegal argument");return u.charCodeAt(i)}))},r.tocodepoint=function(t,r){return v(t,r,(function(t,r,n){e(n,1,2);const i=a(s(n[1],0)),u=o(n[0]);if(0===u.length&&1===n.length)return null;if(u.length<=i||i<0)throw new Error("Illegal argument");return u.codePointAt(i)}))},r.fromcharcode=function(t,r){return v(t,r,(function(t,r,n){if(n.length<1)throw new Error("Function called with wrong number of Parameters");const e=n.map((t=>Math.trunc(a(t)))).filter((t=>t>=0&&t<=65535));return 0===e.length?null:String.fromCharCode.apply(null,e)}))},r.fromcodepoint=function(t,r){return v(t,r,(function(t,r,n){if(n.length<1)throw new Error("Function called with wrong number of Parameters");let e;try{e=n.map((t=>Math.trunc(a(t)))).filter((t=>t<=1114111&&t>>>0===t))}catch(o){return null}return 0===e.length?null:String.fromCodePoint.apply(null,e)}))}}export{O as registerFunctions};