// 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/_base/array dojo/when esri/request ./GeocodeUtil esri/geometry/webMercatorUtils esri/dijit/geoenrichment/utils/FileUtil jimu/portalUtils".split(" "),function(l,q,m,r,t,u,h){return{getAvailableCountries:function(){return h.getPortal(portalUrl).loadSelfInfo().then(function(a){return m({url:(a&&a.helperServices&&a.helperServices.geoenrichment&&a.helperServices.geoenrichment.url?a.helperServices.geoenrichment.url:"https://geoenrich.arcgis.com/arcgis/rest/services/World/geoenrichmentserver")+
"/Geoenrichment/Countries",content:{appID:"webappbuilder",f:"json",langCode:"en-us"},handleAs:"json"})})},createRingOrDriveTimes:function(a){return h.getPortal(portalUrl).loadSelfInfo().then(function(b){return m({url:(b&&b.helperServices&&b.helperServices.geoenrichment&&b.helperServices.geoenrichment.url?b.helperServices.geoenrichment.url:"https://geoenrich.arcgis.com/arcgis/rest/services/World/geoenrichmentserver")+"/Geoenrichment/Enrich",content:{appID:"webappbuilder",f:"json",langCode:"en-us",
useData:JSON.stringify({sourceCountry:a.sourceCountry}),studyAreasOptions:JSON.stringify(a.studyAreasOptions),dataCollections:JSON.stringify(["GlobalIntersect"]),returnGeometry:!0,outSR:JSON.stringify({wkid:102100}),studyAreas:JSON.stringify([{geometry:a.geometry}]),token:esri.id.credentials[0].token},handleAs:"json"})})},createReport:function(a){var b={appID:"webappbuilder",langCode:"en-us",report:"string"===typeof a.report?a.report:JSON.stringify(a.report),format:"pdf",f:"bin",token:esri.id.credentials[0].token,
useData:JSON.stringify({sourceCountry:a.sourceCountry}),studyAreas:JSON.stringify(a.studyAreas),reportFields:JSON.stringify({locationname:a.locationName,latitude:a.lat,longitude:a.long,subtitle:"Prepared by Esri",areadesc2:a.areadesc2})};return h.getPortal(portalUrl).loadSelfInfo().then(function(c){return m({url:(c&&c.helperServices&&c.helperServices.geoenrichment&&c.helperServices.geoenrichment.url?c.helperServices.geoenrichment.url:"https://geoenrich.arcgis.com/arcgis/rest/services/World/geoenrichmentserver")+
"/Geoenrichment/createReport",content:b,handleAs:"blob"}).then(function(d){return u.saveAs(d,a.reportDownloadName+".pdf")}).otherwise(function(d){alert("Error: "+d)})})},checkCapabilities:function(a){return h.getPortal(portalUrl).loadSelfInfo().then(function(b){var c=!1,d=!1,e=b&&b.user&&b.user.privileges,g=b&&b.helperServices;b=g.geoenrichment&&g.geoenrichment.url;g=g.routingUtilities&&g.routingUtilities.url;var n=b?b:"https://geoenrich.arcgis.com/arcgis/rest/services/World/geoenrichmentserver";
!window.isBuilder&&!a.mode&&a.appProxies&&0<a.appProxies.length&&l.some(a.appProxies,function(f){return n.toLowerCase()===f.sourceUrl.toLowerCase()})?d=c=!0:l.forEach(e,function(f){"premium:user:geoenrichment"===f?c=!0:"premium:user:networkanalysis"===f&&(d=!0)});return{hasPrivilege:c&&d,geServiceConfigured:!!b,dirRoutingServiceConfigured:!!g}})},getCountryForPolygon:function(a,b,c){return h.getPortal(portalUrl).loadSelfInfo().then(function(d){return m({url:(d&&d.helperServices&&d.helperServices.geoenrichment&&
d.helperServices.geoenrichment.url?d.helperServices.geoenrichment.url:"https://geoenrich.arcgis.com/arcgis/rest/services/World/geoenrichmentserver")+"/Geoenrichment/Enrich",content:{appID:"webappbuilder",f:"json",langCode:"en-us",dataCollections:JSON.stringify(["GlobalIntersect"]),outSR:JSON.stringify({wkid:102100}),studyAreas:JSON.stringify([{geometry:a.toJson()}]),token:esri.id.credentials[0].token},handleAs:"json"}).then(function(e){if(e&&e.results&&1===e.results.length&&1===e.results[0].value.FeatureSet[0].features.length)return e.results[0].value.FeatureSet[0].features[0].attributes.sourceCountry;
if(e&&e.results&&1===e.results.length&&1<e.results[0].value.FeatureSet[0].features.length){var g=a.getCentroid();g=t.xyToLngLat(g.x,g.y);var n=function(f){var k="";l.forEach(f,function(p){p.attributes.sourceCountry==c&&(k=c)});if(k)return k;l.forEach(f,function(p){p.attributes.sourceCountry==b.defaultCountryID&&(k=defaultCountryID)});return k?k:f[0].attributes.sourceCountry};return q(r.reverseGeocode({x:g[0],y:g[1]})).then(function(f){return f&&f.address&&f.address.CountryCode?f.address.CountryCode:
n(e.results[0].value.FeatureSet[0].features)}).otherwise(function(){return n(e.results[0].value.FeatureSet[0].features)})}return b.defaultCountryID})})},getGEProxyUrl:function(a){var b=!1;return h.getPortal(portalUrl).loadSelfInfo().then(function(c){geUrl=c&&c.helperServices&&c.helperServices.geoenrichment&&c.helperServices.geoenrichment.url?c.helperServices.geoenrichment.url:"https://geoenrich.arcgis.com/arcgis/rest/services/World/geoenrichmentserver";!window.isBuilder&&!a.mode&&a.appProxies&&0<
a.appProxies.length&&l.forEach(a.appProxies,function(d){geUrl.toLowerCase()===d.sourceUrl.toLowerCase()&&(b=d.proxyUrl)});return b})}}});