// 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/dijit/geoenrichment/ReportPlayer/core/supportClasses/templateJsonUtils/fieldInfo/FieldInfoBuilder",["./utils","dojo/i18n!../../../../../../../nls/jsapi"],function(e,m){m=m.geoenrichment.dijit.ReportPlayer.ReportPlayer;var l={createFieldInfoFromCalculator:function(a,h,b,g){if(!a)return null;h=b&&b.format;var f=b&&b.autoformatCurrency;b=b&&b.additionalText;var c={triggerJson:null};c.alias=a.getDescriptionWithType()||a.getAliasWithType();var d=a.variable;c.hasVariable=!0;c.variableID=d.id;
c.vintage=d.vintage;c.fullName=d.fullName;c.fieldCategory=d.fieldCategory;c.type=d.type;var k=a.getToggleGroup&&a.getToggleGroup();c.statefulName=k?k.value:"n/"+d.fullName;k=a.getCalcType().charAt(0);c.name=e.name.createFieldNameFromVariable(d,k);h?e.format.setFieldInfoFormat(c,h):(c.decimals=a.getDecimals(),c.showCurrency=!(!f||"n"!==k||!d.units||"CURRENCY"!==d.units.toUpperCase()),c.showPercent="p"===k,c.useThousandsSeparator=!0);c.additionalText=b;d.isWebMap?(c.isWebMap=!0,c.webMapFieldName=d.fieldName,
c.webMapField=d.field,c.webMapId=d.webMapId,!h&&d.field&&d.field.format&&(c.decimals=d.field.format.places,c.useThousandsSeparator=!1!==d.field.format.digitSeparator)):d.customDataCollection?(c.isCustomDataCollection=!0,c.customDataCollectionId=d.customDataCollection.id,c.customDataCollectionUrl=d.customDataCollection.url,c.customDataCollectionPortalUrl=d.customDataCollection.portalUrl):d.isSiteAttribute&&(c.isSiteAttribute=!0,c.attribute=d.attribute,0<d.attribute.places&&(c.decimals=d.attribute.places));
d.usedFields&&(c.usedFields=d.usedFields);e.name.provideQualifiedFieldInfoTemplateName(c,g);return c},createFieldInfoFromScript:function(a,h,b,g){h=b&&b.format;b=b&&b.additionalText;a=a||{};a.name=a.name||e.name.DEFAULT_SCRIPT_NAME;a.alias=a.alias||m.scriptNameDefault;a.decimals=Number(a.decimals)||0;var f={triggerJson:null};f.name=e.name.createFieldNameFromScript(a);e.name.provideQualifiedFieldInfoTemplateName(f,g);f.script=a;h?e.format.setFieldInfoFormat(f,h):(f.decimals=Number(a.decimals),f.showCurrency=
!1,f.showPercent=!1,f.useThousandsSeparator=!0);f.additionalText=b;return f},createFieldInfoFromChart:function(a){return{isChart:!0,chartJson:a}},createFieldInfoFromImage:function(a,e){return{isImage:!0,imageJson:a,triggerJson:e}},createFieldInfoFromShape:function(a){return{isShape:!0,shapeJson:a}},createFieldInfoFromSection:function(a){return{isReportSection:!0,sectionJson:a}},createFieldInfoFromInfographic:function(a){return{isInfographic:!0,infographicJson:a}},createFieldInfoFromMissingVariable:function(a){return{isMissing:!0,
variable:a,alias:a.alias}}},n=/^\[\w+\]$/,p=/\[\w+\]/;l.createFieldInfoFromLabel=function(a,h){if("string"!==typeof a)return null;a=a.trim();var b=n.test(a);if(!h||b){if(!b)return null;a=a.replace(/\[|\]/g,"").toUpperCase();return l.createFieldInfoFromSpecialFieldName(e.fields.uiToTemplate(a))}return p.test(a)?(b=e.richText.collectFieldInfosFromRenderedXMLString(a))&&e.richText.createFieldInfoFromRichText(b.xmlString,b.fieldInfos,b.specialFieldInfos):null};l.createFieldInfoFromSpecialFieldName=function(a,
h){if("string"!==typeof a)return null;var b;a=a.substr(a.indexOf(".")+1);var g=a.toUpperCase();"CURRDATE"===g?b={name:e.fields.DATE_FIELD_NAME,alias:e.fields.DATE_FIELD_ALIAS,format:h||e.fields.DATE_FIELD_DEFAULT_FORMAT}:"SITENOTE"===g?b={name:e.fields.SITENOTE_FIELD_NAME,alias:e.fields.SITENOTE_FIELD_ALIAS}:"SITENOTES"===g&&(b={name:e.fields.SITENOTES_FIELD_NAME,alias:e.fields.SITENOTES_FIELD_ALIAS});if(b)return b;var f=e.fields.templateToUIHeader(g);f?b={name:e.fields.qualifyTemplateHeaderName(g),
alias:f}:(g=e.fields.templateToUIReportVar(g))&&(b={name:g,alias:g});return b};return l});