// All material copyright ESRI, All Rights Reserved, unless otherwise specified.
// See http://js.arcgis.com/3.23/esri/copyright.txt for details.
//>>built
define("esri/arcade/languageUtils","require exports ../geometry/Geometry ../moment dojo/number ./ImmutableArray ../kernel ./ImmutablePointArray ./ImmutablePathArray dojo/_base/array ../geometry/Point ../geometry/Polyline ../geometry/Polygon ../geometry/Extent ../geometry/Multipoint ./FunctionWrapper".split(" "),function(B,d,w,m,C,p,M,N,O,D,x,P,Q,E,R,S){function q(a,b,c){if(""===b||null===b||void 0===b||b===c||b===c)return a;do a=a.replace(b,c);while(-1!==a.indexOf(b));return a}function y(a){return a instanceof
F||a instanceof S||a instanceof G}function g(a){return"string"===typeof a||a instanceof String}function k(a){return"boolean"===typeof a}function l(a){return"number"===typeof a}function r(a){return a instanceof Array}function h(a){return a instanceof Date}function z(a,b){if(!1===isNaN(a)){if(void 0===b||null===b||""===b)return a.toString();b=q(b,"\u2030","");b=q(b,"\u00a4","");return C.format(a,{pattern:b})}return a.toString()}function u(a,b){var c=m(a);return void 0===b||null===b||""===b?c.format():
c.format(H(b))}function H(a){return a.replace(/(LTS)|L|l/g,function(a){return"["+a+"]"})}function e(a,b,c){switch(c){case "\x3e":return a>b;case "\x3c":return a<b;case "\x3e\x3d":return a>=b;case "\x3c\x3d":return a<=b}return!1}function I(a,b){if(a===b||null===a&&b===d.voidOperation||null===b&&a===d.voidOperation)return!0;if(h(a)&&h(b))return a.getTime()===b.getTime();if(a instanceof O||a instanceof N)return a.equalityTest(b);if(a instanceof x&&b instanceof x){var c=void 0,n=void 0;d.isVersion4?(c=
a.cache._arcadeCacheId,n=b.cache._arcadeCacheId):(c=a.getCacheValue("_arcadeCacheId"),n=b.getCacheValue("_arcadeCacheId"));if(void 0!==c&&null!==c)return c===n}return void 0!==a&&void 0!==b&&null!==a&&null!==b&&"object"===typeof a&&"object"===typeof b&&(a._arcadeCacheId===b._arcadeCacheId&&void 0!==a._arcadeCacheId&&null!==a._arcadeCacheId||a._underlyingGraphic===b._underlyingGraphic&&void 0!==a._underlyingGraphic&&null!==a._underlyingGraphic)?!0:!1}function t(a,b){if(g(a))return a;if(null===a)return"";
if(l(a))return z(a,b);if(k(a))return a.toString();if(h(a))return u(a,b);if(a instanceof w)return JSON.stringify(a.toJson());if(r(a)){for(var c=[],d=0;d<a.length;d++)c[d]=v(a[d]);return"["+c.join(",")+"]"}if(a instanceof p){c=[];for(d=0;d<a.length();d++)c[d]=v(a.get(d));return"["+c.join(",")+"]"}return null!==a&&"object"===typeof a&&void 0!==a.castToText?a.castToText():y(a)?"object, Function":""}function J(a,b){if(g(a))return a;if(null===a)return"";if(l(a))return z(a,b);if(k(a))return a.toString();
if(h(a))return u(a,b);if(a instanceof w)return a instanceof E?'{"xmin":'+a.xmin.toString()+',"ymin":'+a.ymin.toString()+","+(a.hasZ?'"zmin":'+a.zmin.toString()+",":"")+(a.hasM?'"mmin":'+a.mmin.toString()+",":"")+'"xmax":'+a.xmax.toString()+',"ymax":'+a.ymax.toString()+","+(a.hasZ?'"zmax":'+a.zmax.toString()+",":"")+(a.hasM?'"mmax":'+a.mmax.toString()+",":"")+'"spatialReference":'+A(a.spatialReference)+"}":A(a.toJson(),function(a,b){return a.key===b.key?0:"spatialReference"===a.key?1:"spatialReference"===
b.key||a.key<b.key?-1:a.key>b.key?1:0});if(r(a)){for(var c=[],d=0;d<a.length;d++)c[d]=v(a[d]);return"["+c.join(",")+"]"}if(a instanceof p){c=[];for(d=0;d<a.length();d++)c[d]=v(a.get(d));return"["+c.join(",")+"]"}return null!==a&&"object"===typeof a&&void 0!==a.castToText?a.castToText():y(a)?"object, Function":""}function v(a){if(null!==a){if(k(a)||l(a)||g(a))return JSON.stringify(a);if(a instanceof w||a instanceof p||a instanceof Array)return J(a);if(a instanceof Date)return JSON.stringify(u(a,""));
if(null!==a&&"object"===typeof a&&void 0!==a.castToText)return a.castToText()}return"null"}function f(a,b){return l(a)?a:null===a||""===a?0:h(a)?NaN:k(a)?a?1:0:r(a)||""===a||void 0===a?NaN:void 0!==b&&g(a)?(b=q(b,"\u2030",""),b=q(b,"\u00a4",""),C.parse(a,{pattern:b})):a===d.voidOperation?0:Number(a)}function K(a,b){var c;D.some(b.fields,function(b){b.name===a&&(c=b.domain);return!!c});return c}function A(a,b){b||(b={});"function"===typeof b&&(b={cmp:b});var c="boolean"===typeof b.cycles?b.cycles:
!1,d=b.cmp&&function(a){return function(b){return function(c,d){return a({key:c,value:b[c]},{key:d,value:b[d]})}}}(b.cmp),e=[];return function L(a){a&&a.toJson&&"function"===typeof a.toJson&&(a=a.toJson());if(void 0!==a){if("number"===typeof a)return isFinite(a)?""+a:"null";if("object"!==typeof a)return JSON.stringify(a);var b,f;if(Array.isArray(a)){f="[";for(b=0;b<a.length;b++)b&&(f+=","),f+=L(a[b])||"null";return f+"]"}if(null===a)return"null";if(-1!==e.indexOf(a)){if(c)return JSON.stringify("__cycle__");
throw new TypeError("Converting circular structure to JSON");}var g=e.push(a)-1,h=Object.keys(a).sort(d&&d(a));f="";for(b=0;b<h.length;b++){var n=h[b],k=L(a[n]);k&&(f&&(f+=","),f+=JSON.stringify(n)+":"+k)}e.splice(g,1);return"{"+f+"}"}}(a)}Object.defineProperty(d,"__esModule",{value:!0});B=function(){return function(a){this.value=a}}();var T=function(){return function(a){this.value=a}}(),F=function(){return function(a){this.fn=a}}(),G=function(){return function(a){this.fn=a}}();d.NativeFunction=F;
d.ImplicitResult=T;d.ReturnResult=B;d.SizzleFunction=G;d.isVersion4=0===M.version.indexOf("4.");d.voidOperation={type:"VOID"};d.breakResult={type:"BREAK"};d.continueResult={type:"CONTINUE"};d.multiReplace=q;d.isFunctionParameter=y;d.isSimpleType=function(a){return g(a)||l(a)||h(a)||k(a)||null===a||a===d.voidOperation||"number"===typeof a?!0:!1};d.defaultUndefined=function(a,b){return void 0===a?b:a};d.isString=g;d.isBoolean=k;d.isNumber=l;d.isArray=r;d.isFeatureCursor=function(a){return a&&void 0!==
a.isFeatureCursor};d.isImmutableArray=function(a){return a instanceof p};d.isDate=h;d.pcCheck=function(a,b,c){if(a.length<b||a.length>c)throw Error("Function called with wrong number of Parameters");};d.generateUUID=function(){var a=(new Date).getTime();return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(b){var c=(a+16*Math.random())%16|0;a=Math.floor(a/16);return("x"===b?c:c&3|8).toString(16)})};d.formatNumber=z;d.formatDate=u;d.standardiseDateFormat=H;d.greaterThanLessThan=function(a,
b,c){if(null===a){if(null===b||b===d.voidOperation)return e(null,null,c);if(l(b))return e(0,b,c);if(g(b)||k(b))return e(0,f(b),c);if(h(b))return e(0,b.getTime(),c)}if(a===d.voidOperation){if(null===b||b===d.voidOperation)return e(null,null,c);if(l(b))return e(0,b,c);if(g(b)||k(b))return e(0,f(b),c);if(h(b))return e(0,b.getTime(),c)}else if(l(a)){if(l(b))return e(a,b,c);if(k(b))return e(a,f(b),c);if(null===b||b===d.voidOperation)return e(a,0,c);if(g(b))return e(a,f(b),c);if(h(b))return e(a,b.getTime(),
c)}else if(g(a)){if(g(b))return e(t(a),t(b),c);if(h(b))return e(f(a),b.getTime(),c);if(l(b))return e(f(a),b,c);if(null===b||b===d.voidOperation)return e(f(a),0,c);if(k(b))return e(f(a),f(b),c)}else if(h(a)){if(h(b))return e(a,b,c);if(null===b||b===d.voidOperation)return e(a.getTime(),0,c);if(l(b))return e(a.getTime(),b,c);if(k(b)||g(b))return e(a.getTime(),f(b),c)}else if(k(a)){if(k(b))return e(a,b,c);if(l(b))return e(f(a),f(b),c);if(h(b))return e(f(a),b.getTime(),c);if(null===b||b===d.voidOperation)return e(f(a),
0,c);if(g(b))return e(f(a),f(b),c)}return!I(a,b)||"\x3c\x3d"!==c&&"\x3e\x3d"!==c?!1:!0};d.equalityTest=I;d.toString=t;d.toNumberArray=function(a){var b=[];if(!1===r(a))return null;if(a instanceof p){for(var c=0;c<a.length();c++)b[c]=f(a.get(c));return b}for(c=0;c<a.length;c++)b[c]=f(a[c]);return b};d.toStringExplicit=J;d.toNumber=f;d.toDate=function(a,b){if(h(a))return a;if(g(a)){var c=m(a,[void 0===b||null===b||""===b?m.ISO_8601:b]);if(c.isValid())return c.toDate()}return null};d.toDateM=function(a,
b){if(h(a))return m(a);if(g(a)){var c=m(a,[void 0===b||null===b||""===b?m.ISO_8601:b]);if(c.isValid())return c}return null};d.toBoolean=function(a){if(k(a))return a;if(g(a)){if(a=a.toLowerCase(),"true"===a)return!0}else if(l(a))return 0===a||isNaN(a)?!1:!0;return!1};d.fixSpatialReference=function(a,b){if(null===a||void 0===a)return null;if(null===a.spatialReference||void 0===a.spatialReference)a.spatialReference=b;return a};d.fixNullGeometry=function(a){return null===a?null:a instanceof x?"NaN"===
a.x||null===a.x||isNaN(a.x)?null:a:a instanceof Q?0===a.rings.length?null:a:a instanceof P?0===a.paths.length?null:a:a instanceof R?0===a.points.length?null:a:a instanceof E?"NaN"===a.xmin||null===a.xmin||isNaN(a.xmin)?null:a:null};d.getDomainValue=function(a,b){if(!a||!a.domain)return null;var c=null;b="string"===a.field.type||"esriFieldTypeString"===a.field.type?t(b):f(b);for(var d=0;d<a.domain.codedValues.length;d++){var e=a.domain.codedValues[d];e.code===b&&(c=e)}return null===c?null:c.name};
d.getDomainCode=function(a,b){if(!a||!a.domain)return null;var c=null;b=t(b);for(var d=0;d<a.domain.codedValues.length;d++){var e=a.domain.codedValues[d];e.name===b&&(c=e)}return null===c?null:c.code};d.getDomain=function(a,b,c,d){void 0===c&&(c=null);if(!b||!b.fields)return null;for(var e=null,f=0;f<b.fields.length;f++){var h=b.fields[f];h.name.toLowerCase()===a.toString().toLowerCase()&&(e=h)}if(null===e)return null;var g,k;d||(d=c&&b.typeIdField&&c._field(b.typeIdField));null!=d&&D.some(b.types,
function(a){return a.id===d?((g=a.domains&&a.domains[e.name])&&"inherited"===g.type&&(g=K(e.name,b),k=!0),!0):!1});k||g||(g=K(a,b));return{field:e,domain:g}};d.stableStringify=A});