// 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
require({cache:{"url:widgets/Directions/setting/SearchConfig/SearchConfig.html":'\x3cdiv\x3e\r\n  \x3cdiv class\x3d"search-config"\x3e\r\n    \x3cdiv class\x3d"dropdown-button" role\x3d"button"\x3e\r\n      \x3cdiv class\x3d"button"\x3e\r\n        \x3cspan class\x3d"button-text"\x3e${nls.add}\x3c/span\x3e\r\n      \x3c/div\x3e\r\n      \x3cul class\x3d"dropdown-menu" role\x3d"menu" data-dojo-attach-event\x3d"click:_onMenuItemClick"\x3e\r\n        \x3cli class\x3d"dropdown-item" type\x3d"query"\x3e${nls.searchableLayer}\x3c/li\x3e\r\n        \x3cli class\x3d"dropdown-item" type\x3d"locator"\x3e${nls.geocoder}\x3c/li\x3e\r\n      \x3c/ul\x3e\r\n    \x3c/div\x3e\r\n    \x3cdiv class\x3d"sources"\x3e\r\n      \x3cdiv class\x3d"source-list jimu-float-leading"\x3e\r\n        \x3cdiv class\x3d"source-list-table" data-dojo-attach-point\x3d"sourceList"\x3e\x3c/div\x3e\r\n      \x3c/div\x3e\r\n      \x3cdiv class\x3d"source-setting jimu-float-trailing" data-dojo-attach-point\x3d"sourceSettingNode"\x3e\x3c/div\x3e\r\n    \x3c/div\x3e\r\n  \x3c/div\x3e\r\n\x3c/div\x3e'}});
define("dojo/_base/declare dojo/_base/lang dojo/on dojo/_base/html dojo/query dojo/_base/array dojo/Evented dijit/_WidgetBase dijit/_TemplatedMixin dijit/_WidgetsInTemplateMixin dojo/text!./SearchConfig.html ./QuerySourceSetting ./LocatorSourceSetting jimu/LayerInfos/LayerInfos jimu/dijit/LoadingShelter dojo/Deferred ../../searchUtil dojo/when jimu/dijit/Message jimu/dijit/SimpleTable jimu/dijit/RadioBtn".split(" "),function(r,e,g,n,l,m,t,u,v,w,x,p,q,y,z,A,h,B,C,D){return r([u,v,w,t],{templateString:x,
postMixInProperties:function(){this.inherited(arguments);e.mixin(this.nls,window.jimuNls.common)},postCreate:function(){this.inherited(arguments);this.sourceList=new D({autoHeight:!1,selectable:!0,fields:[{name:"name",title:this.nls.name,width:"auto",type:"text",editable:!1},{name:"type",hidden:!0,type:"text",editable:!1},{name:"actions",title:"",width:"70px",type:"actions",actions:["up","down","delete"]}]},this.sourceList);n.setStyle(this.sourceList.domNode,"height","100%");this.sourceList.startup();
this.own(g(this.sourceList,"row-select",e.hitch(this,this._onSourceItemSelected)));this.own(g(this.sourceList,"row-delete",e.hitch(this,this._onSourceItemRemoved)));this.own(g(this.sourceList,"row-edit",e.hitch(this,this._onSourceItemChanged)));this.shelter=new z({hidden:!0})},startup:function(){this.inherited(arguments);this.shelter.show();y.getInstance(this.map,this.map.itemInfo).then(e.hitch(this,function(a){this.layerInfosObj=a;h.setMap(this.map);h.setLayerInfosObj(this.layerInfosObj);h.setAppConfig(this.appConfig);
this._upgradeConfig().then(e.hitch(this,function(){B(h.getConfigInfo(this.config.searchOptions)).then(e.hitch(this,function(c){this.domNode&&(this.setConfig(c),this.shelter.hide())}))}))}))},setConfig:function(a){m.forEach(a.sources,e.hitch(this,function(c,b){var d=this.sourceList.addRow({name:c.name||"",type:c.type});d&&d.success?(this._setRelatedConfig(d.tr,c),0===b&&setTimeout(e.hitch(this,function(){this.sourceList.selectRow(d.tr)}),100)):console.error("add row failed ",d)}))},getConfig:function(a){this._currentSourceSetting&&
this._closeSourceSetting(!0===a?!0:!1);var c={},b=this.sourceList.getRows(),d=[];m.forEach(b,e.hitch(this,function(f){var k=this._getRelatedConfig(f);a&&(delete k._definition,this._removeRelatedConfig(f));d.push(k)}));c.sources=d;return c},destroy:function(){h.setMap(null);h.setLayerInfosObj(null);h.setAppConfig(null);this.inherited(arguments)},validate:function(){return!0},_onMenuItemClick:function(a){this._currentSourceSetting&&!this._currentSourceSetting.isValidConfig()?this._currentSourceSetting.showValidationTip():
(a=a&&a.target&&n.getAttr(a.target,"type"),"locator"===a?this._addNewLocator():"query"===a&&this._addNewQuerySource())},_addNewLocator:function(){this._createNewLocatorSourceSettingFromMenuItem({},{})},_addNewQuerySource:function(){this._createNewQuerySourceSettingFromMenuItem({},{})},_setRelatedConfig:function(a,c){l(a).data("config",e.clone(c))},_getRelatedConfig:function(a){return l(a).data("config")[0]},_removeRelatedConfig:function(a){return l(a).removeData("config")},_createNewLocatorSourceSettingFromMenuItem:function(a,
c){var b=new q({nls:this.nls,map:this.map});b.setDefinition(c);a={url:a.url||"",name:a.name||"",singleLineFieldName:a.singleLineFieldName||"",placeholder:a.placeholder||"",countryCode:a.countryCode||"",maxSuggestions:a.maxSuggestions,searchInCurrentMapExtent:!!a.searchInCurrentMapExtent,type:"locator",maxLocations:a.maxLocations,autoComplete:a.autoComplete,searchDelay:a.searchDelay,minCharacters:a.minCharacters,_isUpgrade:a._isUpgrade};this._upgradeGeocoderConfig(a);b.setConfig(a);b._openLocatorChooser();
b.own(g(b,"select-locator-url-ok",e.hitch(this,function(d){(d=this.sourceList.addRow({name:d.name||"New Geocoder",type:"locator"},this.sourceList.getRows().length))&&d.success&&(this._currentSourceSetting&&this._closeSourceSetting(),b.setRelatedTr(d.tr),b.placeAt(this.sourceSettingNode),this.sourceList.selectRow(d.tr),this._currentSourceSetting=b,this._checkConfig())})));b.own(g(b,"reselect-locator-url-ok",e.hitch(this,function(d){var f=this._currentSourceSetting.getRelatedTr();this.sourceList.editRow(f,
{name:d.name,type:"locator"});this._checkConfig()})));b.own(g(b,"select-locator-url-cancel",e.hitch(this,function(){this._currentSourceSetting!==b&&(b.destroy(),b=null)})))},_createNewLocatorSourceSettingFromSourceList:function(a,c,b){this._currentSourceSetting&&this._closeSourceSetting();this._currentSourceSetting=new q({nls:this.nls,map:this.map});this._currentSourceSetting.setDefinition(c);c={url:a.url||"",name:a.name||"",singleLineFieldName:a.singleLineFieldName||"",placeholder:a.placeholder||
"",countryCode:a.countryCode||"",maxSuggestions:a.maxSuggestions,searchInCurrentMapExtent:!!a.searchInCurrentMapExtent,enableLocalSearch:!!a.enableLocalSearch,localSearchMinScale:a.localSearchMinScale,localSearchDistance:a.localSearchDistance,type:"locator",maxLocations:a.maxLocations,autoComplete:a.autoComplete,searchDelay:a.searchDelay,minCharacters:a.minCharacters,_isUpgrade:a._isUpgrade};this._upgradeGeocoderConfig(c);this._currentSourceSetting.setConfig(c);this._currentSourceSetting.setRelatedTr(b);
this._currentSourceSetting.placeAt(this.sourceSettingNode);this._currentSourceSetting._processlocalSearchTable(!!a.enableLocalSearch);this._currentSourceSetting.own(g(this._currentSourceSetting,"reselect-locator-url-ok",e.hitch(this,function(d){var f=this._currentSourceSetting.getRelatedTr();this.sourceList.editRow(f,{name:d.name,type:"locator"});this._checkConfig()})))},_closeSourceSetting:function(a){var c=this._currentSourceSetting.getRelatedTr(),b=this._currentSourceSetting.getConfig();b._definition=
this._currentSourceSetting.getDefinition();this._setRelatedConfig(c,b);this.sourceList.editRow(c,{name:b.name});"undefined"!==typeof a&&!0!==a||this._currentSourceSetting.destroy()},_createNewQuerySourceSettingFromMenuItem:function(a,c){var b=new p({nls:this.nls,map:this.map,appConfig:this.appConfig});b.setDefinition(c);a={url:a.url,name:a.name||"",layerId:a.layerId,placeholder:a.placeholder||"",searchFields:a.searchFields||[],displayField:a.displayField||c.displayField||"",exactMatch:!!a.exactMatch,
maxSuggestions:a.maxSuggestions,searchInCurrentMapExtent:!!a.searchInCurrentMapExtent,type:"query",maxLocations:a.maxLocations,autoComplete:a.autoComplete,searchDelay:a.searchDelay,minCharacters:a.minCharacters,_isUpgrade:a._isUpgrade};this._upgradeGeocoderConfig(a);b.setConfig(a);b._openQuerySourceChooser();b.own(g(b,"select-query-source-ok",e.hitch(this,function(d){(d=this.sourceList.addRow({name:d.name,type:"query"},0))&&d.success&&(this._currentSourceSetting&&this._closeSourceSetting(),b.setRelatedTr(d.tr),
b.placeAt(this.sourceSettingNode),this.sourceList.selectRow(d.tr),this._currentSourceSetting=b)})));b.own(g(b,"reselect-query-source-ok",e.hitch(this,function(d){var f=this._currentSourceSetting.getRelatedTr();this.sourceList.editRow(f,{name:d.name})})));b.own(g(b,"select-query-source-cancel",e.hitch(this,function(){this._currentSourceSetting!==b&&(b.destroy(),b=null)})))},_createNewQuerySourceSettingFromSourceList:function(a,c,b){this._currentSourceSetting&&this._closeSourceSetting();this._currentSourceSetting=
new p({nls:this.nls,map:this.map,appConfig:this.appConfig});this._currentSourceSetting.placeAt(this.sourceSettingNode);this._currentSourceSetting.setDefinition(c);a={url:a.url,name:a.name||"",layerId:a.layerId,placeholder:a.placeholder||"",searchFields:a.searchFields||[],displayField:a.displayField||c.displayField||"",exactMatch:!!a.exactMatch,maxSuggestions:a.maxSuggestions,searchInCurrentMapExtent:!!a.searchInCurrentMapExtent,type:"query",maxLocations:a.maxLocations,autoComplete:a.autoComplete,
searchDelay:a.searchDelay,minCharacters:a.minCharacters,_isUpgrade:a._isUpgrade};this._upgradeGeocoderConfig(a);this._currentSourceSetting.setConfig(a);this._currentSourceSetting.setRelatedTr(b);this._currentSourceSetting.own(g(this._currentSourceSetting,"reselect-query-source",e.hitch(this,function(d){var f=this._currentSourceSetting.getRelatedTr();this.sourceList.editRow(f,{name:d.name})})))},_onSourceItemRemoved:function(a){this._checkConfig();this._currentSourceSetting&&this._currentSourceSetting.getRelatedTr()===
a&&(this._currentSourceSetting.destroy(),this._currentSourceSetting=null)},_onSourceItemChanged:function(){this._checkConfig()},_checkConfig:function(){!1===this._hasGeoLocator()?this.emit("isConfigValid","false"):this.emit("isConfigValid","true")},_hasGeoLocator:function(){var a=!1,c=this.sourceList.getData();m.some(c,e.hitch(this,function(b){if(b&&"locator"===b.type)return a=!0}));return a},_onSourceItemSelected:function(a){var c=this._getRelatedConfig(a),b=this._currentSourceSetting&&this._currentSourceSetting.tr;
c&&a!==b&&(this._currentSourceSetting&&!this._currentSourceSetting.isValidConfig()?(this._currentSourceSetting.showValidationTip(),this.sourceList.selectRow(b)):"query"===c.type?this._createNewQuerySourceSettingFromSourceList(c,c._definition||{},a):"locator"===c.type&&this._createNewLocatorSourceSettingFromSourceList(c,c._definition||{},a))},_upgradeConfig:function(){var a=new A,c=[],b="";if(h.version.isConfigBefore63(this.config)&&(c=this.config.geocoderOptions&&this.config.geocoderOptions.geocoders)&&
0<c.length){var d=c[0];d&&d.url&&(b=d.url)}b?h.getSingleLineAddressName(b).then(e.hitch(this,function(f){if(f){var k=[];k.push({type:"locator",url:b,name:h.getGeocoderName(b),placeholder:d.placeholder||"",singleLineFieldName:f});this.config.searchOptions={};this.config.searchOptions.sources=k;a.resolve()}else null===f&&(a.resolve(null),new C({message:this.nls.locatorWarning}))}),e.hitch(this,function(){a.resolve(null)})):a.resolve(null);return a},_upgradeGeocoderConfig:function(a){this.config.geocoderOptions&&
(a._oldConfig={},this.config.geocoderOptions.geocoders[0]&&(a._oldConfig.placeholder=this.config.geocoderOptions.geocoders[0].placeholder||""),a._oldConfig.autoComplete=this.config.geocoderOptions.autoComplete,a._oldConfig.maxLocations=this.config.geocoderOptions.maxLocations,a._oldConfig.minCharacters=this.config.geocoderOptions.minCharacters,a._oldConfig.searchDelay=this.config.geocoderOptions.searchDelay)}})});