// 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/PresetDestinations.html":'\x3cdiv\x3e\r\n  \x3cspan class\x3d"title"\x3e${nls.presetDestinations}\x3c/span\x3e\r\n  \x3cdiv data-dojo-attach-point\x3d"shelter" data-dojo-type\x3d"jimu/dijit/LoadingShelter" data-dojo-props\x3d"hidden:true"\x3e\x3c/div\x3e\r\n\r\n  \x3ctable style\x3d"width:98%;" cellspacing\x3d"0"\x3e\r\n    \x3ctbody\x3e\r\n    \x3ctr\x3e\r\n      \x3ctd style\x3d"width:50%;"\x3e\r\n        \x3ctable style\x3d"width:100%;" cellspacing\x3d"0"\x3e\r\n          \x3ctbody\x3e\r\n          \x3ctr\x3e\r\n            \x3ctd style\x3d"width:200px;"\x3e\r\n              \x3cspan class\x3d"impedance-attribute jimu-ellipsis"\x3e${nls.startPoint}\x3c/span\x3e\r\n            \x3c/td\x3e\r\n            \x3ctd style\x3d"width:auto;"\x3e\r\n              \x3cspan data-dojo-attach-point\x3d"startSearchDom" style\x3d"width:220px;"\x3e\x3c/span\x3e\r\n              \x3cdiv data-dojo-attach-point\x3d"startSearchResultsNode" class\x3d"searchResults arcgisSearch"\x3e\x3c/div\x3e\r\n              \x3c!--\x3cdiv data-dojo-attach-point\x3d"startSearchError" class\x3d"hide preset-des-error"\x3eNo Results\x3c/div\x3e--\x3e\r\n            \x3c/td\x3e\r\n\r\n            \x3ctd style\x3d"width:200px;"\x3e\r\n              \x3cspan class\x3d"impedance-attribute jimu-ellipsis"\x3e${nls.endPoint}\x3c/span\x3e\r\n            \x3c/td\x3e\r\n            \x3ctd style\x3d"width:auto;"\x3e\r\n              \x3cspan data-dojo-attach-point\x3d"endSearchDom" class\x3d"end-search" style\x3d"width:220px;"\x3e\x3c/span\x3e\r\n              \x3cdiv data-dojo-attach-point\x3d"endSearchResultsNode" class\x3d"searchResults arcgisSearch"\x3e\x3c/div\x3e\r\n              \x3c!--\x3cdiv data-dojo-attach-point\x3d"endSearchError" class\x3d"hide preset-des-error"\x3eNo Results\x3c/div\x3e--\x3e\r\n            \x3c/td\x3e\r\n          \x3c/tr\x3e\r\n          \x3c/tbody\x3e\r\n        \x3c/table\x3e\r\n      \x3c/td\x3e\r\n    \x3c/tr\x3e\r\n    \x3c/tbody\x3e\r\n  \x3c/table\x3e\r\n\x3c/div\x3e'}});
define("dojo/_base/declare dojo/_base/lang dojo/on dojo/_base/html dojo/query esri/lang dojo/Deferred esri/tasks/locator jimu/utils ../searchUtil jimu/LayerInfos/LayerInfos dojo/when dojo/promise/all dojo/_base/array esri/layers/FeatureLayer dijit/_WidgetBase dijit/_TemplatedMixin dijit/_WidgetsInTemplateMixin dojo/text!./PresetDestinations.html esri/dijit/Search jimu/dijit/RadioBtn".split(" "),function(y,f,n,h,q,z,v,w,r,t,A,B,C,u,D,E,F,G,H,x){return y([E,F,G],{templateString:H,_defaultLocations:null,
_startSearchResults:null,_endSearchResults:null,_isSearchResultsShown:!1,_ERROR_CLASS:"have-error",constructor:function(b){b&&(this._defaultLocations=[],this._defaultLocations=this._parseDefaultLocations(b.defaultLocations),this.nls=b.nls)},postCreate:function(){this.inherited(arguments)},startup:function(){this._getLayerInfos().then(f.hitch(this,function(){this.startSearch=new x({enableSuggestions:!1,enableButtonMode:!1,theme:"arcgisSearch"});this.startSearch.placeAt(this.startSearchDom);this.own(n(this.startSearch,
"search-results",f.hitch(this,"_onStartSearchResults")));this.own(n(this.startSearchResultsNode,"li:click",f.hitch(this,"_onSelectStartSearchResult")));this.own(n(this.startSearch.inputNode,"focus",f.hitch(this,"_onCleanStartError")));this.own(n(this.startSearch.inputNode,"blur",f.hitch(this,function(){!1===this._isSearchResultsShown&&this.startSearch&&this.startSearch.search&&this.startSearch.search()})));this.endSearch=new x({enableSuggestions:!1,enableButtonMode:!1,theme:"arcgisSearch"});this.endSearch.placeAt(this.endSearchDom);
this.own(n(this.endSearch,"search-results",f.hitch(this,"_onEndSearchResults")));this.own(n(this.endSearchResultsNode,"li:click",f.hitch(this,"_onSelectEndSearchResult")));this.own(n(this.endSearch.inputNode,"focus",f.hitch(this,"_onCleanEndError")));this.own(n(this.endSearch.inputNode,"blur",f.hitch(this,function(){!1===this._isSearchResultsShown&&this.endSearch&&this.endSearch.search&&this.endSearch.search()})));this.own(n(window.document,"click",f.hitch(this,function(c){h.isDescendant(c.target,
this.searchResultsNode)||this._hideResultMenu()})));if(this._defaultLocations&&this._defaultLocations.length&&0<this._defaultLocations.length)for(var b=0,a=this._defaultLocations.length;b<a;b++)0===b?this._setSearchValue(this.startSearch,this._defaultLocations[b]):1===b&&this._setSearchValue(this.endSearch,this._defaultLocations[b])}));this.inherited(arguments)},_setSearchValue:function(b,a){"string"===typeof a?b.set("value",a):a.name&&(b.set("selectedResult",a),b.set("value",a.name))},getValue:function(){var b=
[],a=this._getSearchRest(this.startSearch,this._defaultLocations[0]);b.push(a);a=this._getSearchRest(this.endSearch,this._defaultLocations[1]);b.push(a);return b},_getSearchRest:function(b,a){var c=b.selectedResult;if(c)c.feature&&(c.feature._layer&&(c.feature._layer=""),c.feature._sourceLayer&&(c.feature._sourceLayer=""));else if(b.value)c=!1,"string"===typeof a?c=a!==b.value:a.name&&(c=a.name!==b.value),c=c?b.value:a;else return"";return c},_parseDefaultLocations:function(b){for(var a=[],c=0,d=
b.length;c<d;c++)a.push(b[c]);return a},setValue:function(b){b&&0<b.length&&(this._defaultLocations=[],this._defaultLocations=this._parseDefaultLocations(b))},validate:function(){var b=!1;q(".searchLoading",this.domNode).forEach(f.hitch(this,function(){b=!0}));return!1!==b||h.hasClass(this.startSearch,this._ERROR_CLASS)||h.hasClass(this.endSearch,this._ERROR_CLASS)?!1:!0},setSources:function(b){if(b&&b.sources&&b.sources.length)this.shelter.show(),B(t.getConfigInfo(b)).then(f.hitch(this,function(c){return C(this._convertConfig(c)).then(function(d){return u.filter(d,
function(e){return e})})})).then(f.hitch(this,function(c){this.startSearch.set("sources",c);this.endSearch.set("sources",c);this.shelter.hide()}));else if(a&&a.url&&a.singleLineFieldName){var a={locator:new w(a.url||""),outFields:["*"],singleLineFieldName:a.singleLineFieldName};this.startSearch.set("sources",[a]);this.endSearch.set("sources",[a])}else this.startSearch.set("sources",[]),this.endSearch.set("sources",[])},_onCleanError:function(b){h.removeClass(b,this._ERROR_CLASS)},_onCleanStartError:function(){this._onCleanError(this.startSearch)},
_onCleanEndError:function(){this._onCleanError(this.endSearch)},_onStartSearchResults:function(b){this._onSearchResults(b,{searchDijit:this.startSearch,searchResultsNode:this.startSearchResultsNode,searchError:this.startSearchError,results:"start"})},_onEndSearchResults:function(b){this._onSearchResults(b,{searchDijit:this.endSearch,searchResultsNode:this.endSearchResultsNode,searchError:this.endSearchError,results:"end"})},_onSearchResults:function(b,a){var c=a.searchDijit.get("sources"),d=a.searchDijit.get("activeSourceIndex"),
e=a.searchDijit.get("value"),g="",k=b.results;if(""!==e)if(k&&0<b.numResults){"start"===a.results?this._startSearchResults=k:"end"===a.results&&(this._endSearchResults=k);g+='\x3cdiv class\x3d"searchMenu searchResultsMenu" role\x3d"menu"\x3e';for(var l in k)if(k[l]&&k[l].length){b=c[parseInt(l,10)].name;1<c.length&&"all"===d&&(g+='\x3cdiv title\x3d"'+b+'" class\x3d"menuHeader"\x3e'+b+"\x3c/div\x3e");g+="\x3cul\x3e";b=c[l].maxResults||5;e=0;for(var p=k[l].length;e<p&&e<b;e++){if(z.isDefined(k[l][e].name)){var m=
k[l][e].name;m=r.sanitizeHTML(m)}else m=this.nls.untitled;g+='\x3cli title\x3d"'+m+'" data-index\x3d"'+e+'" data-source-index\x3d"'+l+'" role\x3d"menuitem" tabindex\x3d"0"\x3e'+m.toString()+"\x3c/li\x3e"}g+="\x3c/url\x3e"}a.searchResultsNode.innerHTML=g+"\x3c/div\x3e";this._showResultMenu(a.searchDijit,a.searchResultsNode);this._resetSelectorPosition(a.searchDijit,".searchResultsMenu")}else h.addClass(a.searchDijit,this._ERROR_CLASS),this._resetSelectorPosition(a.searchDijit,".noResultsMenu")},_onSelectStartSearchResult:function(b){this._onSelectSearchResult(b,
this.startSearch,this._startSearchResults)},_onSelectEndSearchResult:function(b){this._onSelectSearchResult(b,this.endSearch,this._endSearchResults)},_onSelectSearchResult:function(b,a,c){for(b=b.target;!h.hasAttr(b,"data-source-index")||!h.getAttr(b,"data-index");)b=b.parentNode;var d=null;d=h.getAttr(b,"data-source-index");b=parseInt(h.getAttr(b,"data-index"),10);"all"!==d&&(d=parseInt(d,10));c&&c[d]&&c[d][b]&&(d=c[d][b],a.select(d),d.name&&a.set("value",d.name))},_showResultMenu:function(b,a){h.setStyle(a,
"display","block");q(".searchMenu",a).style("display","block");this._isSearchResultsShown=!0;if(b=q(".searchInputGroup",b.domNode)[0])b={width:h.getMarginBox(b).w+"px"},q(".searchMenu",a).style(b)},_resetSelectorPosition:function(b,a){var c=h.getMarginBox(this.domNode.offsetParent);q(a,this.domNode).forEach(f.hitch(this,function(d){var e=h.position(d),g=h.position(b.domNode);g=".noResultsMenu"===a?0:g.h;e.y+e.h>c.h&&h.setStyle(d,"top",-(e.h+g)-4+"px")}))},_hideResultMenu:function(){q(".searchMenu",
this.domNode).style("display","none");this._isSearchResultsShown=!1},_getLayerInfos:function(){var b=new v;A.getInstance(this.map,this.map.itemInfo).then(f.hitch(this,function(a){this.layerInfosObj=a;this.own(this.layerInfosObj.on("layerInfosFilterChanged",f.hitch(this,function(c){t.config.onLayerInfosFilterChanged(c,this.config)})));b.resolve()}));return b},_convertConfig:function(b){return u.map(b.sources,f.hitch(this,function(a){var c=new v;if(a&&a.url&&"locator"===a.type){var d={locator:new w(a.url||
""),outFields:["*"],singleLineFieldName:a.singleLineFieldName||"",name:r.stripHTML(a.name||""),placeholder:r.stripHTML(a.placeholder||""),countryCode:a.countryCode||"",maxSuggestions:a.maxSuggestions,useMapExtent:!!a.searchInCurrentMapExtent};a.enableLocalSearch&&(d.localSearchOptions={minScale:a.localSearchMinScale,distance:a.localSearchDistance});a.zoomScale&&(d.autoNavigate=!1);c.resolve(d)}else a&&a.url&&"query"===a.type?(d=new D(a.url||null,{outFields:["*"]}),this.own(n(d,"load",f.hitch(this,
function(e){var g=e.layer;e=this.map.getLayer(a.layerId);var k=this.layerInfosObj.getLayerInfoById(a.layerId);e?k=e=!1:k?k=e=!1:(e=!1,k=!0);var l=null;a.searchFields&&0<a.searchFields.length?l=a.searchFields:(l=[],u.forEach(g.fields,function(m){"esriFieldTypeOID"!==m.type&&m.name!==g.objectIdField&&"esriFieldTypeGeometry"!==m.type&&l.push(m.name)}));var p={featureLayer:g,outFields:["*"],searchFields:l,autoNavigate:!1,displayField:a.displayField||"",exactMatch:!!a.exactMatch,name:r.stripHTML(a.name||
""),placeholder:r.stripHTML(a.placeholder||""),maxSuggestions:a.maxSuggestions||6,useMapExtent:!!a.searchInCurrentMapExtent,showInfoWindowOnSelect:e,enableInfoWindow:k,_featureLayerId:a.layerId};p._featureLayerId&&(e=this.layerInfosObj.getLayerInfoById(p._featureLayerId))&&g.setDefinitionExpression(e.getFilter());t.config.getInfoTemplate(g,a,this.layerInfosObj).then(f.hitch(this,function(m){p.infoTemplate=f.clone(m);c.resolve(p)}),f.hitch(this,function(){c.resolve(p)}))}))),this.own(n(d,"error",function(){c.resolve(null)}))):
c.resolve(null);return c}))}})});