text: // All material copyright ESRI, All Rights Reserved, unless otherwise specified.
  // See https://js.arcgis.com/4.9/esri/copyright.txt for details.
  //>>built
  define("require exports ../../core/tsSupport/declareExtendsHelper ../../core/tsSupport/decorateHelper ../../core/tsSupport/assignHelper dojo/i18n!dojo/cldr/nls/number ../../Graphic ../../core/date ../../core/Error ../../core/Handles ../../core/lang ../../core/Logger ../../core/promiseUtils ../../core/watchUtils ../../core/accessorSupport/decorators ../../support/arcadeUtils ../../tasks/support/AttachmentQuery ./support/featureUtils ./support/RelatedFeatures ../support/widget".split(" "),function(Q,
  R,H,n,t,x,I,z,J,K,g,L,p,M,m,u,N,r,O,A){function y(g,d){return g&&"feature"===g.type?g.getField(d):null}function P(g){return g.replace(/[\u00A0-\u99999<>\&]/gim,function(d){return"\x26#"+d.charCodeAt(0)+";"})}var C=L.getLogger("esri.widgets.FeatureViewModel"),D=/^\s*expression\//i,E=new RegExp(""+x.group,"g"),F=new J("cancelled-query","cancelled feature query"),G=z.getFormat("short-date-short-time"),v="DateFormat"+G;return function(B){function d(a){a=B.call(this)||this;a._handles=new K;a._featurePromise=
  void 0;a._layerDateFields=null;a._expressionAttributes=null;a.content=null;a.contentEnabled=!0;a.formattedAttributes=null;a.title="";a.view=null;return a}H(d,B);d.prototype.destroy=function(){this._clear();this._handles.destroy();this._expressionAttributes=this._layerDateFields=this.graphic=this.view=this._handles=null};Object.defineProperty(d.prototype,"graphic",{get:function(){return this._get("graphic")||null},set:function(a){if(a){var b=r.getSourceLayer(a);this._layerDateFields=b?this._getDateFields(b):
  []}this._set("graphic",a);this._graphicChanged(a)},enumerable:!0,configurable:!0});Object.defineProperty(d.prototype,"waitingForContent",{get:function(){return!!this._featurePromise},enumerable:!0,configurable:!0});d.prototype._clear=function(){this._cancelFeatureQuery();this._set("title","");this._set("content",null);this._set("formattedAttributes",null)};d.prototype._graphicChanged=function(a){var b=this,c=this._handles;if(c&&(c.remove("graphic"),this._clear(),a)){c.add(M.watch(this,"graphic.sourceLayer.popupTemplate.title graphic.sourceLayer.popupTemplate.content graphic.sourceLayer.popupTemplate.fieldInfos graphic.popupTemplate.title graphic.popupTemplate.content graphic.popupTemplate.fieldInfos contentEnabled".split(" "),
  function(){b._graphicChanged(b.graphic)}),"graphic");var e=!1;a=this._queryFeature().catch(function(a){a!==F&&C.error("error","error loading template",a)}).then(function(){e=!0;b._featurePromise=null;b.notifyChange("waitingForContent")});e||(this._featurePromise=a,this.notifyChange("waitingForContent"))}};d.prototype._cancelFeatureQuery=function(){var a=this._featurePromise;a&&"function"===typeof a.cancel&&a.cancel(F);this._featurePromise=null;this.notifyChange("waitingForContent")};d.prototype._compileContent=
  function(a,b){var c=this;if(a&&(a.nodeName||a&&A.isWidgetBase(a)||A.isWidget(a)))return a;if("string"===typeof a)return this._compileText({type:"text",text:a}).text;if(Array.isArray(a))return a.map(function(a,f){f=(f=b&&b[f])&&f.value;var e=a.type;if("attachments"===e)return c._compileAttachments(a,f);if("fields"===e)return c._compileFields(a);if("media"===e)return c._compileMedia(a);if("text"===e)return c._compileText(a)});a&&C.warn("invalid content type.")};d.prototype._compileFields=function(a){var b=
  this,c=this.graphic;a=g.clone(a);var e=(c=c.getEffectivePopupTemplate())&&c.expressionInfos,c=a.fieldInfos?void 0:c&&c.fieldInfos,c=a.fieldInfos||g.clone(c),f=[];c&&c.forEach(function(a){var c=a.fieldName.toLowerCase();if(!a.hasOwnProperty("visible")||a.visible)c=b._isExpressionField(c)?b._getExpressionInfo(e,c):null,a.label=c?c.title:a.label,f.push(a)});a.fieldInfos=f;return a};d.prototype._setImageValue=function(a){var b=a.value,c=a.formattedAttributes;a=a.layer;var e=b.linkURL,f=b.sourceURL;f&&
  (f=this._fixTokens(f,a),b.sourceURL=this._substituteAttributes(c,f));e&&(a=this._fixTokens(e,a),b.linkURL=this._substituteAttributes(c,a))};d.prototype._compileMedia=function(a){var b=this,c=this._expressionAttributes,e=this._layerDateFields,f=this.graphic;a=g.clone(a);var d=a.mediaInfos||[],h=t({},f.attributes,c),w=r.getSourceLayer(f),k=this.formattedAttributes.global,q={dateFormat:{properties:e,formatter:v}};a.mediaInfos=d.map(function(a){if(a=g.clone(a)){var c=a.value,e=a.type,f=a.title?b._processFieldsInLinks(a.title,
  h):"",d=a.caption?b._processFieldsInLinks(a.caption,h):"";a.title=f?b._substituteAttributes(k,f,q):"";a.caption=d?b._substituteAttributes(k,d,q):"";if("image"===e)return b._setImageValue({value:c,formattedAttributes:k,layer:w}),a.value.sourceURL?a:void 0;if("pie-chart"===e||"line-chart"===e||"column-chart"===e||"bar-chart"===e)return b._setChartValue({value:c,attributes:h,formattedAttributes:k,layer:w}),a}}).filter(Boolean);return a};d.prototype._substituteAttributes=function(a,b,c){return(""+this._removeEmptyHref(g.substitute(a,
  b,c))).trim()};d.prototype._compileText=function(a){var b=this._expressionAttributes,c=this._layerDateFields,e=this.graphic;(a=g.clone(a))&&a.text&&(e=t({},e.attributes,b),b=this.formattedAttributes.global,c={dateFormat:{properties:c,formatter:v}},e=this._processFieldsInLinks(a.text,e),a.text=this._substituteAttributes(b,e,c));return a};d.prototype._compileTitle=function(){var a=this._expressionAttributes,b=this._layerDateFields,c=this.graphic,e=c.getEffectivePopupTemplate(),e=e&&e.title,a=t({},c.attributes,
  a),b={dateFormat:{properties:b,formatter:v}},f=this.formattedAttributes.global;return"function"===typeof e?e.call(null,{graphic:c}):"string"===typeof e&&e?(c=this._processFieldsInLinks(e,a),this._substituteAttributes(f,c,b)):""};d.prototype._getExpressionInfo=function(a,b){if(this._isExpressionField(b)){var c=b.replace(D,"").toLowerCase(),e;a.some(function(a){if(a.name.toLowerCase()===c)return e=a,!0});return e}};d.prototype._fixTokens=function(a,b){return a.replace(/(\{([^\{\r\n]+)\})/g,function(a,
  e,f){return(a=y(b,f))?"{"+a.name+"}":e})};d.prototype._encodeAttributes=function(a){var b=a?g.clone(a):{};Object.keys(b).forEach(function(a){var c=b[a];"string"===typeof c&&(c=encodeURIComponent(c).replace(/\'/g,"\x26apos;"),b[a]=c)});return b};d.prototype._formatAttributesToFieldInfos=function(a,b,c){var e=this,f=g.clone(this._layerDateFields);a.forEach(function(d){var l=e._getFixedFieldName(d.fieldName,b);d.fieldName=l;c[l]=e._formatValue(c[l],{fieldInfos:a,fieldName:l,layer:b});f&&d.format&&d.format.dateFormat&&
  (d=f.indexOf(l),-1<d&&f.splice(d,1))})};d.prototype._getArcadeViewingMode=function(a){return a&&"local"===a.viewingMode?"localScene":"globalScene"};d.prototype._getViewInfo=function(){var a=this.view;if(a){var b="3d"===a.type?this._getArcadeViewingMode(a):"map";return u.getViewInfo({viewingMode:b,scale:a.scale,spatialReference:a.spatialReference})}};d.prototype._formatAttributes=function(a){var b=this,c=this._expressionAttributes,e=this.graphic,f=e.attributes,e=r.getSourceLayer(e),d=f?g.clone(f):
  {},h=t({},d,c);this.addRelatedFeatureAttributes(h);a&&this._formatAttributesToFieldInfos(a,e,h);if(e){var w=e.typeIdField;f&&Object.keys(f).forEach(function(a){if(!b.isRelatedField(a)){var c=f[a];null!=c&&(c=b._getDomainName(a,c),null!=c?h[a]=c:a===w&&(c=b._getTypeName(),null!=c&&(h[a]=c)))}})}return h};d.prototype._formatValue=function(a,b){var c={dateFormat:{properties:this._layerDateFields,formatter:v}},e=b.fieldName,f=this._getFieldInfo(b.fieldInfos,e),d=g.clone(f),f=b.preventPlacesFormatting;
  (b=y(b.layer,e))&&"date"===b.type&&(b=d.format||{},b.dateFormat=b.dateFormat||"short-date-short-time",d.format=b);e=d&&d.format;if(null==a||!d||null==e)return a;var h=[],d=e.hasOwnProperty("places")||e.hasOwnProperty("digitSeparator");b=e.hasOwnProperty("digitSeparator")?e.digitSeparator:!0;f=null!=e.places&&(!f||0<e.places);d&&f&&h.push("places: "+Number(e.places));f=d?f?"NumberFormat("+h.join(",")+")":"NumberFormat":e.dateFormat?"DateFormat"+(z.getFormat(e.dateFormat)||G):void 0;if(!f)return a;
  a=g.substitute({myKey:a},"{myKey:"+f+"}",c)||"";return d&&!b&&x.group?a.replace(E,""):a};d.prototype._getDomainName=function(a,b){var c=this.graphic,e=r.getSourceLayer(c);return e&&"feature"===e.type?(a=e.getFieldDomain(a,{feature:c}))&&"coded-value"===a.type?a.getName(b):null:null};d.prototype._getFieldInfo=function(a,b){if(a&&a.length&&b){var c=b.toLowerCase(),e=void 0;a.some(function(a){if(a.fieldName&&a.fieldName.toLowerCase()===c)return e=a,!0});return e}};d.prototype._getTypeName=function(){var a=
  this.graphic,b=r.getSourceLayer(a);if(b&&"feature"===b.type&&(a=b.getFeatureType(a)))return a.name};d.prototype._removeEmptyHref=function(a){return a.replace(/href=(""|'')/gi,"")};d.prototype._processFieldsInLinks=function(a,b){var c=this.get("graphic.layer");a=this._fixTokens(a,c);var e=this._encodeAttributes(b),c=/href\s*=\s*(?:\"([^\"]+)\"|\'([^\']+)\')/gi;return a?a.replace(c,function(a,c,d){c=(""+(c||d)).trim();return g.substitute(c&&"{"===c[0]?b:e,a)}):a};d.prototype._compileAttachments=function(a,
  b){a=g.clone(a);if(!b)return a;a.attachmentInfos=b;return a};d.prototype._queryAttachments=function(){var a=this.graphic,b=r.getSourceLayer(a);if(!b)return p.resolve([]);if((b="scene"===b.type&&b.associatedLayer?b.associatedLayer:b)&&"feature"===b.type){var c=b.objectIdField,e=(a=a.attributes)&&a[c],a=new N({objectIds:[e]});return b.queryAttachments(a).then(function(a){return a[e]||[]})}return p.resolve([])};d.prototype._queryContentElements=function(a){var b=this;if(!Array.isArray(a))return p.resolve();
  var c={};a.forEach(function(a,d){"attachments"===a.type&&(a=b._queryAttachments())&&(c[d]=a)});return Object.keys(c).length?p.eachAlways(c):p.resolve()};d.prototype._getContent=function(){var a=this.graphic;if(!this.contentEnabled)return p.resolve();var b=a.getEffectivePopupTemplate(),b=b&&b.content,a="function"===typeof b?b.call(null,{graphic:a}):b;return p.isThenable(a)?a:p.resolve(a)};d.prototype._queryFeature=function(){var a=this;return this._getContent().then(function(b){return a._checkForRelatedFeatures(b).then(function(){a._expressionAttributes=
  a._createFormattedExpressions();a._set("formattedAttributes",a._createFormattedAttributes(b));a._set("title",a._compileTitle());return a._queryContentElements(b).then(function(c){c=a._compileContent(b,c);a._set("content",c||null);return c})})})};d.prototype._isExpressionField=function(a){return D.test(a)};d.prototype._createCompiledExpressionDictionary=function(a){var b=new Map;if(!a)return b;a.forEach(function(a){return b.set(a.name,u.createFunction(a.expression))});return b};d.prototype._getDateFields=
  function(a){return(a=a.fields)?a.filter(function(a){return"date"===a.type}).map(function(a){return a.name}):[]};d.prototype._createFormattedExpressions=function(){var a=this,b=this.graphic,c=b.getEffectivePopupTemplate(),c=c&&c.expressionInfos,e=this._createCompiledExpressionDictionary(c),d={};c&&c.forEach(function(c){var f="expression/"+c.name;c=e.get(c.name);var l=a._getViewInfo();c=u.executeFunction(c,u.createExecContext(b,l));d[f]="string"===typeof c?P(c):c});return d};d.prototype._createFormattedAttributes=
  function(a){var b=this,c=this.graphic.getEffectivePopupTemplate(),e={global:this._formatAttributes(c&&c.fieldInfos),content:[]};Array.isArray(a)&&a.forEach(function(a,c){"fields"===a.type&&a.fieldInfos&&(e.content[c]=b._formatAttributes(a.fieldInfos))});return e};d.prototype._getAllFieldInfos=function(a){var b=[],c=this.graphic.getEffectivePopupTemplate();(c=c&&c.fieldInfos)&&b.push.apply(b,c);if(!a||!Array.isArray(a))return b;a.forEach(function(a){b.push.apply(b,a&&a.fieldInfos)});return b};d.prototype._checkForRelatedFeatures=
  function(a){var b=this.graphic;a=this._getAllFieldInfos(a);return this.queryRelatedInfos(b,a)};d.prototype._getChartOption=function(a){var b=a.value,c=a.attributes,e=a.formattedAttributes,d=a.fieldName,l=a.relatedFieldName,h=a.fieldInfos;a=r.getSourceLayer(this.graphic);var g=b.normalizeField,k=b.tooltipField,g=g?this.isRelatedField(g)?c[this.getRelatedFieldInfo(g).fieldName]:c[g]:null,b=l&&void 0!==c[l]?c[l]:void 0!==c[d]?c[d]:e[d],b="string"===typeof b&&x.group?parseFloat(b.replace(E,"")):b,q=void 0===
  b?null:b&&g?b/g:b,b={y:q};if(this.isRelatedField(d))return e=this.getRelatedFieldInfo(d),d=(d=this.getRelatedFieldInfo(k))?d.fieldName:null,a=this._formatValue(q,{fieldInfos:h,fieldName:l,layer:a,preventPlacesFormatting:!!g}),l=e?e.label||e.fieldName:l,b.tooltip=(d&&void 0!==c[d]?c[d]:l)+": "+a,b;c=this._getFieldInfo(h,d);l=this._getFixedFieldName(d,a);c=c?c.label||c.fieldName:d;b.tooltip=(k&&void 0!==e[k]?e[k]:c)+": "+e[l];return b};d.prototype._getFixedFieldName=function(a,b){return(b=y(b,a))?b.name:
  a};d.prototype._getFixedFieldNames=function(a,b){var c=this;return a&&a.map(function(a){return c._getFixedFieldName(a,b)})};d.prototype._setChartValue=function(a){var b=this,c=a.value,d=a.attributes,f=a.formattedAttributes,g=a.layer,h=this.graphic,m=this.relatedInfoCount;a=c.fields;var k=c.normalizeField;c.fields=this._getFixedFieldNames(a,g);k&&(c.normalizeField=this._getFixedFieldName(k,g));if(a.some(function(a){return!!(null!=f[a]||b.isRelatedField(a)&&m)})){var q=(g=h.getEffectivePopupTemplate())&&
  g.fieldInfos;c.chartOptions=c.chartOptions||[];a.forEach(function(a){b.isRelatedField(a)?c.chartOptions=c.chartOptions.concat(b._getRelatedChartInfos({fieldInfos:q,fieldName:a,formattedAttributes:f,value:c})):(a=b._getChartOption({value:c,attributes:d,formattedAttributes:f,fieldName:a,fieldInfos:q}),c.chartOptions.push(a))})}};d.prototype._getRelatedChartInfos=function(a){var b=this,c=a.fieldInfos,d=a.fieldName,f=a.formattedAttributes,g=a.value,h=[];a=this.getRelatedFieldInfo(d);var m=a.fieldName,
  k=this.getRelatedInfo(a.layerId);if(!k)return h;a=k.relatedFeatures;k=k.relation;if(!k||!a)return h;k=k.cardinality;a.forEach(function(a){var e=a.attributes;e&&Object.keys(e).forEach(function(a){a===m&&h.push(b._getChartOption({value:g,attributes:e,formattedAttributes:f,fieldName:d,relatedFieldName:a,fieldInfos:c}))})});return"one-to-many"===k||"many-to-many"===k?h:[h[0]]};n([m.property({readOnly:!0})],d.prototype,"content",void 0);n([m.property()],d.prototype,"contentEnabled",void 0);n([m.property({readOnly:!0})],
  d.prototype,"formattedAttributes",void 0);n([m.property({type:I})],d.prototype,"graphic",null);n([m.property({readOnly:!0})],d.prototype,"title",void 0);n([m.property()],d.prototype,"view",void 0);n([m.property({readOnly:!0})],d.prototype,"waitingForContent",null);return d=n([m.subclass("esri.widgets.FeatureViewModel")],d)}(m.declared(O))});