// 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/InfographicsOptions","../../declare dojo/_base/lang dojo/Deferred dojo/string ../../tasks/geoenrichment/studyAreaOptionsFromJson ../../tasks/geoenrichment/GeoenrichmentTask ./lang ./config ./InfographicsOptionsItem".split(" "),function(h,z,A,F,B,C,m,p,v){function D(a,c){var b=parseFloat(a.index),e=parseFloat(c.index);return isNaN(b)&&isNaN(e)?0:isNaN(b)?1:isNaN(e)?-1:b-e}function w(a,c){for(var b=0;b<a.length;b++){var e=a[b];if(e.type==c.type&&m.arraysEqual(e.variables,
c.variables))return{report:e,index:b}}return null}function x(a,c){if(a)for(var b in a)if(a.hasOwnProperty(b)){c[b]=[];for(var e=0;e<a[b].length;e++){var g={};y(a[b][e],g);c[b].push(g)}}}function y(a,c){c.type=a.type||("OneVarMultiComparison"==a.report?"OneVar":a.report);if(a.dataCollection)if(a.vars){c.variables=[];for(var b=0;b<a.vars.length;b++)c.variables.push(a.dataCollection+"."+a.vars[b])}else c.variables=[a.dataCollection+".*"];else c.variables=a.variables;m.isBoolean(a.isVisible)?c.isVisible=
a.isVisible:m.isBoolean(a.checked)&&(c.isVisible=a.checked)}h=h("esri.dijit.geoenrichment.InfographicsOptions",null,{_items:null,_loaded:null,_loadPromises:null,studyAreaOptions:null,theme:"common",constructor:function(a){this._loaded={};this._loadPromises={};this.studyAreaOptions=B(a&&(a.buffer||a.studyAreaOptions));this._items={};if(a){var c=a.reports||a.items;if(c){x(c,this._items);for(var b in c)c[b]&&c[b].length&&(this._loaded[b]=!0)}a.theme&&(this.theme=a.theme)}},toJson:function(){var a={};
x(this._items,a);return{studyAreaOptions:this.studyAreaOptions.toJson(),items:a,theme:this.theme}},getItems:function(a){var c=new A;if(this._loaded[a])c.resolve(this._items[a]);else{if(this._loadPromises[a])return this._loadPromises[a];var b=new C(p.server);b.token=p.token;b.getDataCollections(a,null,["id","alias"]).then(z.hitch(this,this._mergeItems,a,c),function(a){c.reject(a)})}return this._loadPromises[a]=c.promise},_mergeItems:function(a,c,b){try{var e={AgePyramid:1,TapestryNEW:1,RelatedVariables:1,
OneVar:1},g={TapestryNEW:"Tapestry"},d,n,k=[];for(d=0;d<b.length;d++){var h=b[d].metadata.infographics||b[d].metadata.infographics2;if(h){var q=JSON.parse(h),l;for(l in q)if(e[l]){var r=new v(g[l]||l,[b[d].id+".*"]),t;for(t in q[l])q[l].hasOwnProperty(t)&&(r[t]=q[l][t]);(n=w(k,r))?k[n.index]=r:k.push(r)}}}var u,f=this._items[a];f||(f=[],f.push(new v("OneVar",["KeyGlobalFacts.AVGHHSZ"])),this._items[a]=f);for(d=f.length-1;0<=d;d--)if(n=w(k,f[d]))y(f[d],n.report),f[d]=n.report,k.splice(n.index,1);else{if("OneVar"==
f[d].type&&1==f[d].variables.length){var m,p=f[d].variables[0];if(!u)for(u={},e=0;e<b.length;e++)for(g=0;g<b[e].variables.length;g++)u[b[e].id+"."+b[e].variables[g].id]=b[e].variables[g];if(m=u[p]){f[d].title=m.alias;continue}}f.splice(d,1);d--}for(d=0;d<k.length;d++)f.push(k[d]);f.sort(D);this._loaded[a]=!0;delete this._loadPromises[a];c.resolve(f)}catch(E){c.reject(E)}}});h.Item=v;return h});