// All material copyright ESRI, All Rights Reserved, unless otherwise specified.
// See http://@sbaseurl@/jsapi/jsapi/esri/copyright.txt and http://www.arcgis.com/apps/webappbuilder/copyright.txt for details.

//>>built
define("dojo/_base/array dojo/_base/lang dojo/Deferred dojo/promise/all dojo/string esri/arcade/arcade esri/arcade/Feature esri/ArcadeExpression esri/arcadeProfiles/popupProfile esri/tasks/RelationshipQuery jimu/utils jimu/LayerStructure".split(" "),function(k,n,r,D,w,x,E,F,u,G,H,I){var d={readExprInfo:{}};d.readExprInfo.getArcadeProfilesByType=function(a,b,c){a={map:a,layer:b};return"render"===c?d.readExprInfo._getArcadeRender(a):"label"===c?d.readExprInfo._getArcadeLabel(a):"infoTemplate"===c?d.readExprInfo._getArcadeInfoTemplate(a):
d.readExprInfo._getAllArcade(a)};d.readExprInfo._getArcadeRender=function(a){return d.readExprInfo._lookupArcadeRender({layers:d.readExprInfo._checkPassInLayer(a)})};d.readExprInfo._getArcadeInfoTemplate=function(a){return d.readExprInfo._lookupArcadeInfoTemplate({layers:d.readExprInfo._checkPassInLayer(a)})};d.readExprInfo._getArcadeLabel=function(a){return d.readExprInfo._lookupArcadeLabel({layers:d.readExprInfo._checkPassInLayer(a)})};d.readExprInfo._getAllArcade=function(a){var b=d.readExprInfo._getArcadeRender(a),
c=d.readExprInfo._getArcadeInfoTemplate(a);a=d.readExprInfo._getArcadeLabel(a);return{render:b,infoTemplate:c,label:a}};d.readExprInfo._checkPassInLayer=function(a){var b=[];return b="undefined"!==typeof a?"undefined"!==typeof a.layer?null!==a.layer&&""!==a.layer?d.readExprInfo._getAllMapLayers(a):d.readExprInfo._getAllMapLayers():d.readExprInfo._getAllMapLayers():d.readExprInfo._getAllMapLayers()};d.readExprInfo._getAllMapLayers=function(a){var b="",c=[],e=I.getInstance();a&&a.layer&&(b=a.layer.id);
""!==b?(a=e.getNodeById(b))&&c.push(a._layerInfo.layerObject):e.traversal(function(f){"undefined"!==typeof f._layerInfo.layerObject.type?-1===f._layerInfo.layerObject.type.indexOf("tile")&&c.push(f._layerInfo.layerObject):c.push(f._layerInfo.layerObject)});return c};d.readExprInfo._lookupArcadeRender=function(a){var b=[];0<a.layers.length&&k.forEach(a.layers,n.hitch(this,function(c){var e={};if("undefined"!==typeof c.renderer){var f=c.renderer;"undefined"!==typeof f.valueExpression&&(e.layer=c.id,
e.valueExpression=f.valueExpression,e.valueExpressionTitle=f.valueExpressionTitle,"undefined"!==typeof f.values&&(e.values=f.values),"undefined"!==typeof f.visualVariables&&(e.visualVariables=f.visualVariables));1<Object.keys(e).length&&e.constructor===Object?b.push(e):b.push({layer:c.id,valueExpression:null,valueExpressionTitle:null,values:null,visualVariables:null})}}));return b};d.readExprInfo._lookupArcadeInfoTemplate=function(a){var b=[];0<a.layers.length&&k.forEach(a.layers,n.hitch(this,function(c){var e=
{};if("undefined"!==typeof c.infoTemplate)"undefined"!==typeof c.infoTemplate.info.expressionInfos&&0<c.infoTemplate.info.expressionInfos.length&&(e.layer=c.id,e.expressionInfos=c.infoTemplate.info.expressionInfos);else if("undefined"!==typeof c.infoTemplates)for(var f in c.infoTemplates)if(c.infoTemplates.hasOwnProperty(f)&&"undefined"!==typeof c.infoTemplates[f].infoTemplate.info.expressionInfos){var g=c.infoTemplates[f].infoTemplate;0<g.info.expressionInfos.length&&(e.layer=c.id,e.expressionInfos=
g.info.expressionInfos)}1<Object.keys(e).length&&e.constructor===Object?b.push(e):b.push({layer:c.id,expressionInfos:null})}));return b};d.readExprInfo._lookupArcadeLabel=function(a){var b=[];0<a.layers.length&&k.forEach(a.layers,n.hitch(this,function(c){var e={};"undefined"!==typeof c.labelingInfo&&k.forEach(c.labelingInfo,n.hitch(this,function(f){"undefined"!==typeof f.name&&(e.layer=c.id,e.name=f.name,e.labelingInfo=f,e.expression=f.labelExpressionInfo.expression)}));1<Object.keys(e).length&&e.constructor===
Object?b.push(e):b.push({layer:c.id,name:null,labelingInfo:null,expression:null})}));return b};d.compileExpressions=function(a){var b={};k.forEach(a,function(c){c.returnType&&c.returnType.toLowerCase();b[c.name]=new F({expression:c.expression,returnType:"number"===c.returnType?"number":"string",profile:u})});return b};d.isAsync=function(a,b,c){var e="",f;for(f in b)if(0<=a.indexOf("expression/")&&f===a.split("expression/")[1]){e=f;break}return(a=(b?b:d.compileExpressions(c))[e])&&u.isAsync(a)};d.customExpr=
{};d.customExpr.getAttributesFromCustomArcadeExpr=function(a,b,c){a=d.InfoTemplate._parseArcadeExpressions(a);return d.InfoTemplate._combineFeatureAttributesAndExpressionResolutions(b,a,c)};d.customExpr.getAsynAttributesFromCustomArcadeExpr=function(a,b,c,e){var f=n.mixin({},b.attributes);if(a)for(var g in a)f["expression/"+g]=b.evaluateExpression(a[g],u.getEvalOptions({expression:a[g],feature:b,layer:c,map:e,spatialReference:e&&e.spatialReference}));return f};d.customExpr.getAttributesValueFromCustomArcadeExprBatch=
function(a,b,c){var e=[],f;for(f in b)e.push(b[f]);b=d.InfoTemplate._parseArcadeExpressions(a);a=d.InfoTemplate._getExprNamesArrayFromPopupExprInfos(a);a.relationships=null;a.parsedExpressions=b;var g=new r;d.InfoTemplate._getPopupFieldsValueFromArcadeFeatures(e,a,c).then(function(h){g.resolve(h)});return g};d.InfoTemplate={};d.InfoTemplate.getAttributesFromInfoTemplate=function(a,b,c){var e={fields:[]};b.layerObject&&b.layerObject.fields&&(e.fields=b.layerObject.fields);a=d.readExprInfo.getArcadeProfilesByType(a,
b,"infoTemplate")[0].expressionInfos;if(!a)return c.attributes;a=d.InfoTemplate._parseArcadeExpressions(a);return d.InfoTemplate._combineFeatureAttributesAndExpressionResolutions(c,a,e)};d.InfoTemplate.getAttributesValueFromInfoTemplateBatch=function(a,b,c){var e={fields:[]};b.layerObject&&b.layerObject.fields&&(e.fields=b.layerObject.fields);var f=[];for(h in c)f.push(c[h]);a=d.readExprInfo.getArcadeProfilesByType(a,b,"infoTemplate")[0].expressionInfos;var g=new r;if(!a)return g.resolve([]),g;c=
d.InfoTemplate._parseArcadeExpressions(a);var h=null;h=b.getPopupInfo().description;null!==h?(h=d.InfoTemplate._convertPopupDescToFieldNamesArray(h),h.relationships=d.InfoTemplate._getRelationshipQueries(b)):(h=d.InfoTemplate._getExprNamesArrayFromPopupExprInfos(a),h.relationships=null);h.parsedExpressions=c;d.InfoTemplate._getPopupFieldsValueFromArcadeFeatures(f,h,e).then(function(l){g.resolve(l)});return g};d.InfoTemplate._getRelationshipQueries=function(a){var b=!1,c={},e=/\d+/,f;if(f=a.getPopupInfo().description.match(/\{relationships\/\d+\//gm))b=
!0,k.forEach(f,function(g){var h=g.match(e)[0];c.hasOwnProperty(h)||(g=new G,g.outFields=["*"],g.relationshipId=h,g.returnGeometry=!1,c[h]={operLayer:a,relatedQuery:g})});return b?c:null};d.InfoTemplate._getExprNamesArrayFromPopupExprInfos=function(a){var b=[],c;for(c in a)b.push("${expression/"+a[c].name+"}");return b};d.InfoTemplate._convertPopupDescToFieldNamesArray=function(a){a=d.InfoTemplate._convertEndParasToEOLs(a);a=d.InfoTemplate._convertBreaksToEOLs(a);a=d.InfoTemplate._sanitizeNoTags(a).trim();
a=a.replace(/\{/gi,"${");a=a.replace(/\u00a0/gi," ");a=a.split("\n");return a=k.map(a,function(b){return b.trim()})};d.InfoTemplate._sanitizeNoTags=function(a){var b=H.sanitizeHTML(a);a=/<(?:!--(?:(?:-*[^->])*--+|-?)|script\b(?:[^"'>]|"[^"]*"|'[^']*')*>[\s\S]*?<\/script\s*|style\b(?:[^"'>]|"[^"]*"|'[^']*')*>[\s\S]*?<\/style\s*|\/?[a-z](?:[^"'>]|"[^"]*"|'[^']*')*)>/gi;do{var c=b;b=b.replace(a,"")}while(b!==c);return b=b.replace(/</g,"\x26lt;")};d.InfoTemplate._getPopupFieldsValueFromArcadeFeatures=
function(a,b,c){var e=new r,f=[],g=[],h=0;b.relationships?(k.forEach(a,function(l){d.InfoTemplate._objEach(b.relationships,function(m,p){var y=new r,z=m.relatedQuery;g.push(y);var t=l.attributes[m.operLayer.layerObject.objectIdField];z.objectIds=[t];m.operLayer.layerObject.queryRelatedFeatures(z,function(q){var A=[];q[t]&&q[t].features&&(q=q[t].features,k.forEach(q,function(J){var B=[],C;var K=l.attributes;var L="relationships/"+p+"/";d.InfoTemplate._objEach(J.attributes,function(v,M){C=L+M;K[C]=
v});k.forEach(b,function(v){B.push(w.substitute(v,d.InfoTemplate._combineFeatureAttributesAndExpressionResolutions(l,b.parsedExpressions,c),d.InfoTemplate._useEmptyStringForNull))});A.push(B)}));y.resolve(A)})})}),D(g).then(function(l){k.forEach(l,function(m){k.forEach(m,function(p){++h;f.push(p)})});console.log(h+" related address features found");e.resolve(f)})):(k.forEach(a,function(l){var m=[];k.forEach(b,function(p){m.push(w.substitute(p,d.InfoTemplate._combineFeatureAttributesAndExpressionResolutions(l,
b.parsedExpressions,c),d.InfoTemplate._useEmptyStringForNull))});f.push(m)}),e.resolve(f));return e};d.InfoTemplate._parseArcadeExpressions=function(a){if(Array.isArray(a)&&0<a.length){var b={};k.forEach(a,function(c){b[c.name]=x.parseScript(c.expression)})}return b};d.InfoTemplate._initArcadeContext=function(a,b){var c={vars:{}};c.vars.$feature=E.createFromGraphicLikeObject(a.geometry,a.attributes,b);return c};d.InfoTemplate._combineFeatureAttributesAndExpressionResolutions=function(a,b,c){var e;
var f=n.mixin({},a.attributes);if(b)for(e in a=d.InfoTemplate._initArcadeContext(a,c),b)c=x.executeScript(b[e],a),f["expression/"+e]=c?c.toString():"";return f};d.InfoTemplate._convertEndParasToEOLs=function(a){var b=a;a=a.match(/<\/p>/gi);k.forEach(a,function(c){b=b.replace(c,"\n")});return b};d.InfoTemplate._convertBreaksToEOLs=function(a){var b=a;a=a.match(/<br\s*\/?>/gi);k.forEach(a,function(c){b=b.replace(c,"\n")});return b};d.InfoTemplate._useEmptyStringForNull=function(a){return a?a:""};d.InfoTemplate._objEach=
function(a,b,c){for(var e in a)a.hasOwnProperty(e)&&b.call(c,a[e],e)};return d});