// 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/kernel dojo/_base/lang dojo/Deferred dojo/promise/all esri/arcade/arcade esri/arcade/Feature esri/support/expressionUtils esri/arcadeProfiles/utils esri/graphic ./generalUtils".split(" "),function(l,F,y,q,v,z,G,w,H,I,J){var g={convertPopupToLabelSpec:function(a){var b=[];var c=a.description;var e=a.fieldInfos;var d=a.expressionInfos;a=J.sanitizeNoTags(g.convertBreaksToEOLs(g.convertEndParasToEOLs(c))).trim();a=a.replace(/\{/gi,"${");a=a.replace(/\u00a0/gi," ");
a=a.split("\n");a=l.map(a,function(f){var n="";f=f.replace(/\{([^}]+)\}/g,function(r,p){var k;l.some(e,function(h){if(h.fieldName.toLowerCase()===p.toLowerCase()){k=h.fieldName;var m=h.label||h.fieldName;if(!h.hasOwnProperty("label")&&d)for(h=0;h<d.length;h++)m==="expression/"+d[h].name&&(m=d[h].title);n=""===n?m:n+" "+m;return!0}});return k?p?"{"+k+"}":r:p?"{"+p+"}":r});b.push(n);return f.trim()});a.csvHeaderRow=b;return a},createLabelsFromFeatures:function(a,b,c,e){var d=new q,f=[],n=[],r=0;g.layer=
c;g.map=e;g.expressionInfos=b.expressionInfos;if(b.relationships)l.forEach(a,function(k){g.objEach(b.relationships,function(h,m){var A=new q,B=h.relatedQuery;n.push(A);var x=k.attributes[h.operLayer.layerObject.objectIdField];B.objectIds=[x];h.operLayer.layerObject.queryRelatedFeatures(B,function(t){var C=[];t[x]&&t[x].features&&(t=t[x].features,l.forEach(t,function(u){var D;var E=k.attributes;var K="relationships/"+m+"/";g.objEach(u.attributes,function(L,M){D=K+M;E[D]=L});u=new I(k.geometry,null,
E);C.push(g.populateLabelLines(u,b))}));v(C).then(function(u){A.resolve(u)})})})}),v(n).then(function(k){l.forEach(k,function(h){l.forEach(h,function(m){++r;f.push(m)})});console.log(r+" related address features found");d.resolve(f)});else{var p=[];l.forEach(a,function(k){p.push(g.populateLabelLines(k,b))});v(p).then(function(k){d.resolve(k)})}return d},populateLabelLines:function(a,b){var c=new q,e=[];g.combineFeatureAttributesAndExpressionResolutions(a,b.parsedExpressions).then(function(d){l.forEach(b,
function(f){e.push(g.substitute(f,d,g.useEmptyStringForNull))});c.resolve(e)});return c.promise},substitute:function(a,b,c){var e=F.global;c=c?y.hitch(e,c):function(d){return d};return a.replace(/\$\{([^\s:\}]*)(?::([^\s:\}]+))?\}/g,function(d,f){if(""===f)return"$";d=c(b[f],f);if("undefined"===typeof d)throw Error('string.substitute could not find key "'+f+'" in template');return d.toString()})},parseArcadeExpressions:function(a){if(Array.isArray(a)&&0<a.length){var b={};l.forEach(a,function(c){b[c.name]=
z.parseScript(c.expression)})}return b},initArcadeContext:function(a){var b=null,c=null,e=null,d=null;g.expressionInfos&&(e=g.expressionInfos);g.map&&(c=g.map);g.layer&&g.layer.layerObject&&(b=g.layer.layerObject);a&&a.geometry&&a.geometry.spatialReference&&(d=a.geometry.spatialReference);return g.getEvalOptions({expression:e,feature:a,layer:b,map:c,sr:d}).context},getEvalOptions:function(a){var b=a.feature,c=a.layer,e=a.map;a=a.spatialReference;b=b?G.createFromGraphicLikeObject(b.geometry,b.attributes,
c):null;if(c){var d={spatialReference:a};var f=c.getMap()?w.createFeatureSetFromLayer(c,d):w.createFeatureSetFromLayerUrl(c.url,d);d=(c=H.getServiceUrl(c.url))?w.createFeatureSetCollectionFromServiceUrl(c,d):null}e=e?w.createFeatureSetCollectionFromMap(e):null;return{context:{vars:{$feature:b,$layer:f,$datastore:d,$map:e},spatialReference:a}}},combineFeatureAttributesAndExpressionResolutions:function(a,b){var c=new q,e=[],d;var f=y.mixin({},a.attributes);if(b){a=g.initArcadeContext(a);for(d in b)e.push(g.executeArcadeExpression(d,
b[d],a,f));v(e).then(function(){c.resolve(f)})}else c.resolve(f);return c.promise},executeArcadeExpression:function(a,b,c,e){var d=new q;(b=z.executeScript(b,c))&&b.then?b.then(function(f){e["expression/"+a]=f?f.toString():"";d.resolve(f)},function(f){e["expression/"+a]=f?f.toString():"";d.resolve(f)}):(e["expression/"+a]=b?b.toString():"",d.resolve(b));return d.promise},convertEndParasToEOLs:function(a){var b=a;a=a.match(/<\/p>/gi);l.forEach(a,function(c){b=b.replace(c,"\n")});return b},convertBreaksToEOLs:function(a){var b=
a;a=a.match(/<br\s*\/?>/gi);l.forEach(a,function(c){b=b.replace(c,"\n")});return b},useEmptyStringForNull:function(a){return a?a:""},objEach:function(a,b,c){for(var e in a)a.hasOwnProperty(e)&&b.call(c,a[e],e)}};return g});