// 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/_base/declare dojo/on dojo/when esri/dijit/geoenrichment/_Wizard esri/geometry/webMercatorUtils ./CreateBuffersPage ./ErrorPage ./RunReportsPage ./SelectPointPolygonPage ./utils/GEUtil ./utils/GeocodeUtil".split(" "),function(h,l,d,e,m,k,n,p,q,r,f,t){return l([m],{selectedPoint:{tradeAreas:[]},selectedPolygon:{},selectedCountryID:"",availableCountries:[],drawnPolygonGraphic:null,name:"BusinessAnalystWizard",baseClass:"jimu-widget-business-analyst-wizard",postCreate:function(){this.inherited(arguments);
var a=this;e(f.checkCapabilities(this.appConfig),function(b){b.hasPrivilege&&b.geServiceConfigured&&b.dirRoutingServiceConfigured?(a.pages.SELECT_POINT_POLYGON=new r({map:a.map,nls:a.nls,wizard:a,config:a.config,onNext:function(){a._loadCreateBuffersPage()}}),a.pages.CREATE_BUFFERS=new n({map:a.map,nls:a.nls,wizard:a,config:a.config,onBack:function(){a._loadSelectPointPolygonPage()},onNext:function(){a._loadRunReportsPage()}}),a.pages.CREATE_BUFFERS.startup(),a.pages.RUN_REPORTS=new q({map:a.map,
nls:a.nls,wizard:a,appConfig:a.appConfig,config:a.config,onBack:function(){a.selectedPoint.geometry?a._loadCreateBuffersPage():a._loadSelectPointPolygonPage()}}),a.loadPage("SELECT_POINT_POLYGON"),a.own(d(a.map.infoWindow,"Show",function(){a._featureSelected()})),a.own(d(a.map.infoWindow,"Hide",function(){a._featureUnselected()})),a.own(d(a.map.infoWindow,"set-features",function(){a._featureSelected()})),a.own(d(a.map.infoWindow,"selection-change",function(){a._featureSelected()})),a.selectedCountryID=
a.config.defaultCountryID,e(f.getAvailableCountries(),function(c){a.availableCountries=c.countries;a.setSelectedCountry(a.selectedCountryID)}),a.map.infoWindow&&a.map.infoWindow.features&&0<a.map.infoWindow.features.length&&a._featureSelected()):(a.pages.ERROR_PAGE=new p({nls:a.nls,displayErrors:{gePrivilege:!b.hasPrivilege,geServiceNotConfigured:!b.geServiceConfigured,dirRoutingServiceNotConfigured:!b.dirRoutingServiceConfigured}}),a.pages.ERROR_PAGE.startup(),a.loadPage("ERROR_PAGE"))})},startup:function(){},
resize:function(){this.pages.SELECT_POINT_POLYGON&&this.pages.SELECT_POINT_POLYGON.resize()},clearSelectedPointBuffers:function(){var a=this;h.forEach(this.selectedPoint.tradeAreas,function(b){b&&b.graphic&&a.map.graphics.remove(b.graphic)});this.selectedPoint.tradeAreas=[]},clearSelectedPoint:function(){this.clearSelectedPointBuffers();this.map.graphics.remove(this.selectedPoint.pointGraphic);this.selectedPoint={tradeAreas:[]}},clearSelectedPolygon:function(){this.selectedPolygon={};this.drawnPolygonGraphic&&
(this.map.infoWindow.clearFeatures(),this.map.graphics.remove(this.drawnPolygonGraphic),this.drawnPolygonGraphic=null)},setSelectedCountry:function(a){var b=this;3==a.length?h.forEach(this.availableCountries,function(c){c.abbr3==a&&(b.selectedCountryID=c.id)}):2==a.length&&(this.selectedCountryID=a);this.pages.RUN_REPORTS.loadReportsInfographicsForCountry(this.selectedCountryID)},_loadSelectPointPolygonPage:function(){this.clearSelectedPoint();this.clearSelectedPolygon();this.loadPage("SELECT_POINT_POLYGON");
this.resize()},_loadCreateBuffersPage:function(){this.loadPage("CREATE_BUFFERS");this.pages.CREATE_BUFFERS.refresh()},_loadRunReportsPage:function(){this.loadPage("RUN_REPORTS");this.pages.RUN_REPORTS.refresh()},refreshPage:function(){this.currentPage&&this.currentPage.refresh&&this.currentPage.refresh()},_featureSelected:function(){var a=this,b=-1<this.map.infoWindow.selectedIndex&&this.map.infoWindow.features&&this.map.infoWindow.features[this.map.infoWindow.selectedIndex];if(!b)this.clearSelectedPoint(),
this.clearSelectedPolygon();else if((this.selectedPoint.geometry?this.selectedPoint.geometry:this.selectedPolygon.geometry)!==b.geometry)if(this.clearSelectedPoint(),this.clearSelectedPolygon(),"point"===b.geometry.type){this.selectedPoint.geometry=b.geometry;this.selectedPoint.locationName=this._getFeatureName(b);this.selectedPoint.attributes=b.attributes?b.attributes:{};var c=k.xyToLngLat(b.geometry.x,b.geometry.y);this.selectedPoint.long=c[0].toFixed(5);this.selectedPoint.lat=c[1].toFixed(5);e(t.reverseGeocode({x:c[0],
y:c[1]}),function(g){a.setSelectedCountry(g.address.CountryCode);a._loadCreateBuffersPage()})}else"polygon"==b.geometry.type?(this.selectedPolygon.geometry=b.geometry,this.selectedPolygon.locationName=this._getFeatureName(b),this.selectedPolygon.feature=b,c=b.geometry.getCentroid(),c=k.xyToLngLat(c.x,c.y),e(f.getCountryForPolygon(b.geometry,this.config,this.selectedCountryID),function(g){a.setSelectedCountry(g);a._loadRunReportsPage()})):a._loadSelectPointPolygonPage()},_featureUnselected:function(){this.clearSelectedPoint();
this.clearSelectedPolygon();this.pages.SELECT_POINT_POLYGON.search&&this.pages.SELECT_POINT_POLYGON.search.clear();this._loadSelectPointPolygonPage()},_getFeatureName:function(a){return a.getTitle()?a.getTitle():a._layer.displayField&&a.attributes[a._layer.displayField]?a.attributes[a._layer.displayField]:""}})});