// 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/dataProviders/supportClasses/ReportDataProcessor","dojo/_base/lang dojo/when dojo/promise/all ./tasks/EnrichAreasTask ./tasks/RunReportTask ./AreaDataUtil ./CustomReportsManager ./attachments/AttributesUtil esri/dijit/geoenrichment/utils/DateUtil ../../core/supportClasses/templateJsonUtils/fieldInfo/FieldInfoNameUtil ../../core/supportClasses/templateJsonUtils/fieldInfo/FieldLibrary ../../core/infographics/dataDrilling/EnrichUtil ./tasks/parsers/FeatureSetParser".split(" "),
function(x,h,l,q,r,d,m,t,n,e,p,u,v){var f={ENRICHED_DATA_NO_LEVELS:"enrichFieldData_noLevels",addFeatureAttributesCalculator:function(a,b){for(var c in a.attributes)d.setAreaDataObjectValue(c,a.attributes[c],b,e.AREA_ATTRIBUTES_CALCULATOR_NAME)},addAreaInfoCalculator:function(a,b){d.setAreaDataObjectValue("SITE_NAME",a.name||a.shortName||"",b,e.AREA_ATTRIBUTES_CALCULATOR_NAME);d.setAreaDataObjectValue("STORE_NAME",a.name||a.shortName||"",b,e.AREA_ATTRIBUTES_CALCULATOR_NAME);d.setAreaDataObjectValue("AREA_DESC",
a.description||"",b,e.AREA_ATTRIBUTES_CALCULATOR_NAME);d.setAreaDataObjectValue("AREA_DESC2",a.description||"",b,e.AREA_ATTRIBUTES_CALCULATOR_NAME);d.setAreaDataObjectValue("AREA_DESC3",a.description||"",b,e.AREA_ATTRIBUTES_CALCULATOR_NAME);d.setAreaDataObjectValue("STORE_ADDR",a.address||"",b,e.AREA_ATTRIBUTES_CALCULATOR_NAME);d.setAreaDataObjectValue("STORE_LAT",a.latitude||"",b,e.AREA_ATTRIBUTES_CALCULATOR_NAME);d.setAreaDataObjectValue("STORE_LONG",a.longitude||"",b,e.AREA_ATTRIBUTES_CALCULATOR_NAME)},
addEnrichFeatureSet:function(a,b,c,w){a=v.parse(a,c||f.ENRICHED_DATA_NO_LEVELS,function(a){return b[a]||a});d.mergeAreaData(a,w.fieldData.areaData)}};return{populateReportDataFromAttachmentsStore:function(a,b){var c=[];c.push(h(b.getNotes(),function(b){b&&b.length&&(a.fieldData.metadata[p.SITENOTE_FIELD_NAME]=b[0].text,a.fieldData.metadata[p.SITENOTES_FIELD_NAME]=b.map(function(a){return a.text}).join("\x3cbr/\x3e\x3cbr/\x3e"))}));c.push(h(b.getAttributes(),function(b){if(!b||!b.length)return null;
var c={attributes:{}};b.forEach(function(b){c.attributes[b.name]=t.formatAttributeValue(b)});a.analysisAreas.forEach(function(b,g){var d=a.fieldData.areaData[g];d&&f.addFeatureAttributesCalculator(c,d)})}));return l(c)},runReportAndGetData:function(a){return h(m.getCustomReportByID(a),function(b){return(new r).execute({geoenrichmentUrl:a.geoenrichmentUrl,analysisAreas:a.analysisAreas,countryID:a.countryID,hierarchy:b.hierarchy,report:{reportID:b.reportID,portalUrl:b.templateData.getPortalUrl(!0),
modified:b.modified},cacheResult:!0}).then(function(a){return{taskID:a.taskID,selectedReport:b,areaData:a.areaData}},function(b){a.fieldData.errors.push(b);return null})})},applyRunReportAndGetDataResults:function(a,b){a&&a.areaData&&(b.fieldData.runReportTaskID=a.taskID,b.fieldData.areaData=a.areaData,b.analysisAreas&&this._reportDataFromAreas(b.analysisAreas,b.fieldData.areaData),a.selectedReport&&this._reportDataFromReport(a.selectedReport,b.fieldData))},_reportDataFromAreas:function(a,b){a.forEach(function(a,
d){var c=b[d];c&&(f.addFeatureAttributesCalculator(a.feature,c),f.addAreaInfoCalculator(a,c))})},_reportDataFromReport:function(a,b){var c=b.metadata;a&&!c.Title&&(c.Title=a.title);c.Source="Esri";c.Date=n.getReportFooterDate();c.Copyright="\u00a9"+n.getFullYear()+" Esri";c.ProductLabel="";c.ProductUrl="";c.PhoneNumber="";c.TrialUrlText=""},enrichFieldData:function(a,b){function c(a,c,e){function g(a){return b.fieldData.areaData.every(function(c,g){return void 0!==d.getAreaDataValue(a,b.fieldData,
e,g,!0)})}var k=[],f={};a.forEach(function(a){g(a.fieldName)||(k.push(a.mapTo),f[a.mapTo]=a.fieldName,f[a.mapTo.substr(a.mapTo.indexOf(".")+1)]=a.fieldName)});return k.length?{fields:k,fieldsMap:f,comparisonLevels:c,calculatorName:e}:null}var e=[];a=u.optimizeInfos(a);a.forEach(function(a){var b;if(a.isGeneral||a.isChart)b=c(a.fields,a.levels,a.calculatorName);b&&e.push(b)});if(e.length)return h(m.getCustomReportByID(b),function(a){function c(a){b.fieldData.errors.push(a)}return l(e.map(function(d){return(new q).enrichAreas({geoenrichmentUrl:b.geoenrichmentUrl,
analysisAreas:b.analysisAreas,countryID:b.countryID,hierarchy:a.hierarchy,fields:d.fields,comparisonLevels:d.comparisonLevels}).then(function(a){f.addEnrichFeatureSet(a[0],d.fieldsMap,d.calculatorName,b)},c)}))})}}});