// 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/Deferred dojo/promise/all dojo/when dojo/_base/array esri/request jimu/portalUtils dojo/i18n!../nls/strings".split(" "),function(t,x,v,l,w,y,q){STANDARD_INFOGRAPHIC_TYPEKEYWORD="esriReportPlayerStandardInfographic";return{_ownedCachedCustomReports:null,_sharedCachedCustomReports:null,_cachedCountryClassicReports:[],_cachedInfographicReports:null,_countryInitDfds:[],getAvailableClassicReports:function(b,e){var a=this,d=[],h=new t,c;e&&l.forEach(e.countryConfig,function(m){b==m.countryID&&
(c=m)});c||(c={countryID:b,allowEsriReports:!0,allowAllEsriReports:!0,allowEsriInfographics:!0,allowAllEsriInfographics:!0,allowMyReports:!0,allowMyInfographics:!0,allowSharedReports:!0,allowSharedInfographics:!0,allowAllOrgReports:!0,allowAllOrgInfographics:!0,defaultInfographicID:"",defaultReportID:"",enabledEsriReports:[],enabledOrgReports:[],enabledEsriInfographics:[],enabledOrgInfographics:[]});var k=null,p=null,r=null;v(this._initReports(b),function(){if(!e||c.allowAllEsriReports||a._hasEnabledReports(a._cachedCountryClassicReports[b],
c.enabledEsriReports))k=d.length,d.push({value:"esriReports",label:q.esriReports,children:[]});if(!e||c.allowAllOrgReports&&a._hasReportsForCountry(a._ownedCachedCustomReports,b)||a._hasEnabledReportsForCountry(a._ownedCachedCustomReports,b,c.enabledOrgReports))p=d.length,d.push({value:"myReports",label:q.myReports,children:[]});if(!e||c.allowAllOrgReports&&a._hasReportsForCountry(a._sharedCachedCustomReports,b)||a._hasEnabledReportsForCountry(a._sharedCachedCustomReports,b,c.enabledOrgReports))r=
d.length,d.push({value:"sharedReports",label:q.sharedReports,children:[]});(c.allowAllEsriReports||a._hasEnabledReports(a._cachedCountryClassicReports[b],c.enabledEsriReports))&&a._cachedCountryClassicReports[b]&&0<a._cachedCountryClassicReports[b].length&&l.forEach(a._cachedCountryClassicReports[b],function(g){(c.allowAllEsriReports||c.enabledEsriReports.includes(g.reportID))&&d[k].children.push(a._formatClassicReportsForDropDown(g))});var m=["esriWebInfographicReport","esriWebSingleInfographic",
"esriWebBlankInfographic","esriWebHiddenInfographic","esriWebComparisonReport"];(c.allowAllOrgReports&&a._hasReportsForCountry(a._ownedCachedCustomReports,b)||a._hasEnabledReportsForCountry(a._ownedCachedCustomReports,b,c.enabledOrgReports))&&l.forEach(a._ownedCachedCustomReports,function(g){g.properties.countries.includes(b)&&(c.allowAllOrgReports||c.enabledOrgReports.includes(g.id))&&(g.typeKeywords.some(function(n){return 0<=m.indexOf(n)})||d[p].children.push(a._formatClassicReportsForDropDown(g)))});
(c.allowAllOrgReports&&a._hasReportsForCountry(a._sharedCachedCustomReports,b)||a._hasEnabledReportsForCountry(a._sharedCachedCustomReports,b,c.enabledOrgReports))&&l.forEach(a._sharedCachedCustomReports,function(g){g.properties.countries.includes(b)&&(c.allowAllOrgReports||c.enabledOrgReports.includes(g.id))&&(g.typeKeywords.some(function(n){return 0<=m.indexOf(n)})||d[r].children.push(a._formatClassicReportsForDropDown(g)))});var f=function(g,n){g=g.label.toUpperCase();n=n.label.toUpperCase();var u=
0;g>n?u=1:g<n&&(u=-1);return u};0<d.length&&d[0].children.sort(f);1<d.length&&d[1].children.sort(f);2<d.length&&d[2].children.sort(f);h.resolve(d)});return h},_hasEnabledReports:function(b,e){return b&&e?l.some(b,function(a){return e.includes(a.reportID)}):!1},_hasReportsForCountry:function(b,e){return b&&e?l.some(b,function(a){return a.properties.countries.includes(e)}):!1},_hasEnabledReportsForCountry:function(b,e,a){return b&&e&&a?l.some(b,function(d){return d.properties.countries.includes(e)?
a.includes(d.id):!1}):!1},_formatClassicReportsForDropDown:function(b){return b.metadata?{label:b.metadata.title,value:b.reportID,reportType:b.metadata.type}:{label:b.title,value:b.id,reportType:b.properties.type,item:{itemid:b.id,url:portalUrl,token:esri.id.credentials[0].token}}},getAvailableInfographicReports:function(b,e){var a=this,d=[],h=new t,c;e&&l.forEach(e.countryConfig,function(m){b==m.countryID&&(c=m)});c||(c={countryID:b,allowEsriReports:!0,allowAllEsriReports:!0,allowEsriInfographics:!0,
allowAllEsriInfographics:!0,allowMyReports:!0,allowMyInfographics:!0,allowSharedReports:!0,allowSharedInfographics:!0,allowAllOrgReports:!0,allowAllOrgInfographics:!0,defaultInfographicID:"",defaultReportID:"",enabledEsriReports:[],enabledOrgReports:[],enabledEsriInfographics:[],enabledOrgInfographics:[]});var k=null,p=null,r=null;v(this._initReports(b),function(){if(!e||c.allowAllEsriInfographics||a._hasEnabledInfographics(a._cachedInfographicReports,c.enabledEsriInfographics))k=d.length,d.push({value:"esriReports",
label:q.esriInfographics,children:[]});if(!e||c.allowAllOrgInfographics&&0<a._ownedCachedCustomReports.length||a._hasEnabledInfographics(a._ownedCachedCustomReports,c.enabledOrgInfographics))p=d.length,d.push({value:"myReports",label:q.myInfographics,children:[]});if(!e||c.allowAllOrgInfographics&&0<a._sharedCachedCustomReports.length||a._hasEnabledInfographics(a._sharedCachedCustomReports,c.enabledOrgInfographics))r=d.length,d.push({value:"sharedReports",label:q.sharedInfographics,children:[]});
(c.allowAllEsriInfographics||a._hasEnabledInfographics(a._cachedInfographicReports,c.enabledEsriInfographics))&&l.forEach(a._cachedInfographicReports,function(f){f.properties.countries.includes(b)&&(c.allowAllEsriInfographics||c.enabledEsriInfographics.includes(f.id))&&d[k].children.push(a._formatInfographicReportsForDropDown(f))});(c.allowAllOrgInfographics&&0<a._ownedCachedCustomReports.length||a._hasEnabledInfographics(a._ownedCachedCustomReports,c.enabledOrgInfographics))&&l.forEach(a._ownedCachedCustomReports,
function(f){f.properties.countries.includes(b)&&(c.allowAllOrgInfographics||c.enabledOrgInfographics.includes(f.id))&&(f.typeKeywords.includes("esriWebInfographicReport")||a._isOldPortalInfographic(f))&&d[p].children.push(a._formatInfographicReportsForDropDown(f))});(c.allowAllOrgInfographics&&0<a._sharedCachedCustomReports.length||a._hasEnabledInfographics(a._sharedCachedCustomReports,c.enabledOrgInfographics))&&l.forEach(a._sharedCachedCustomReports,function(f){f.properties.countries.includes(b)&&
(c.allowAllOrgInfographics||c.enabledOrgInfographics.includes(f.id))&&(f.typeKeywords.includes("esriWebInfographicReport")||a._isOldPortalInfographic(f))&&d[r].children.push(a._formatInfographicReportsForDropDown(f))});var m=function(f,g){f=f.label.toUpperCase();g=g.label.toUpperCase();var n=0;f>g?n=1:f<g&&(n=-1);return n};0<d.length&&d[0].children.sort(m);1<d.length&&d[1].children.sort(m);2<d.length&&d[2].children.sort(m);h.resolve(d)});return h},_hasEnabledInfographics:function(b,e){return l.some(b,
function(a){return e.includes(a.id)})},_isOldPortalInfographic:function(b){return b.properties&&b.properties.isHidden&&"true"===b.properties.isHidden?!1:b.properties&&b.properties.isGraphicReport&&"true"===b.properties.isGraphicReport?!0:!1},_formatInfographicReportsForDropDown:function(b){return{label:b.title,value:b.id}},_initReports:function(b){var e=[],a=this;if(this._countryInitDfds[b])return this._countryInitDfds[b];this._countryInitDfds[b]=new t;var d=function(h,c){return w(h).then(function(k){l.forEach(k.results,
function(p){c.push(p)});if(-1!=k.nextStart)return h.content.start=k.nextStart,d(h,c)},function(k){alert(k)})};y.getPortal(portalUrl).loadSelfInfo().then(function(h){var c=h&&h.helperServices&&h.helperServices.geoenrichment&&h.helperServices.geoenrichment.url?h.helperServices.geoenrichment.url:"https://geoenrich.arcgis.com/arcgis/rest/services/World/geoenrichmentserver";a._cachedCountryClassicReports[b]||e.push(w({url:c+"/Geoenrichment/reports/"+b,content:{appID:"webappbuilder",f:"json",langCode:"en-us"}}).then(function(k){a._cachedCountryClassicReports[b]=
k.reports},function(k){alert(k)}));a._cachedInfographicReports||(a._cachedInfographicReports=[],e.push(d({url:portalUrl+"/sharing/rest/search",content:{appID:"webappbuilder",f:"json",start:1,num:100,sortField:"modified",sortOrder:"desc",q:"typekeywords:(esriWebStandardInfographicReport)"}},a._cachedInfographicReports)));a._ownedCachedCustomReports||(a._ownedCachedCustomReports=[],e.push(d({url:portalUrl+"/sharing/rest/search",content:{appID:"webappbuilder",f:"json",start:1,num:100,sortField:"modified",
sortOrder:"desc",q:'type:"Report Template" typekeywords:(esriWebReport NOT esriWebSingleInfographic) owner:'+esri.id.credentials[0].userId}},a._ownedCachedCustomReports)));a._sharedCachedCustomReports||(a._sharedCachedCustomReports=[],e.push(d({url:portalUrl+"/sharing/rest/search",content:{appID:"webappbuilder",f:"json",start:1,num:100,sortField:"modified",sortOrder:"desc",q:'access:shared type:"Report Template" typekeywords:(esriWebReport NOT esriWebSingleInfographic) NOT owner:'+esri.id.credentials[0].userId}},
a._sharedCachedCustomReports)),e.push(d({url:portalUrl+"/sharing/rest/search",content:{appID:"webappbuilder",f:"json",start:1,num:100,sortField:"modified",sortOrder:"desc",q:'access:org type:"Report Template" typekeywords:(esriWebReport NOT esriWebSingleInfographic) NOT owner:'+esri.id.credentials[0].userId}},a._sharedCachedCustomReports)),h&&h.appInfo&&h.appInfo.orgId&&e.push(d({url:portalUrl+"/sharing/rest/search",content:{appID:"webappbuilder",f:"json",start:1,num:100,sortField:"modified",sortOrder:"desc",
q:'access:public type:"Report Template" typekeywords:(esriWebReport NOT esriWebSingleInfographic) NOT owner:'+esri.id.credentials[0].userId+" orgid: "+h.id}},a._sharedCachedCustomReports)));0===e.length?a._countryInitDfds[b].resolve():x(e).then(function(){a._countryInitDfds[b].resolve()})});return this._countryInitDfds[b]}}});