// COPYRIGHT © 201 Esri
//
// All rights reserved under the copyright laws of the United States
// and applicable international laws, treaties, and conventions.
//
// This material is licensed for use under the Esri Master License
// Agreement (MLA), and is bound by the terms of that agreement.
// You may redistribute and use this code without modification,
// provided you adhere to the terms of the MLA and include this
// copyright notice.
//
// See use restrictions at http://www.esri.com/legal/pdfs/mla_e204_e300/english
//
// For additional information, contact:
// Environmental Systems Research Institute, Inc.
// Attn: Contracts and Legal Services Department
// 380 New York Street
// Redlands, California, USA 92373
// USA
//
// email: contracts@esri.com
//
// See http://js.arcgis.com/3.31/esri/copyright.txt for details.

define(["require","dojo/_base/declare","dojo/_base/lang","dojo/_base/array","dojo/Evented","dojo/Deferred","dojo/keys","dojo/on","dojo/query","dojo/uacss","dojo/regexp","dojo/dom","dojo/dom-attr","dojo/dom-class","dojo/dom-style","dojo/dom-construct","dojo/date/locale","dojo/i18n!../nls/jsapi","dojo/text!./Search/templates/Search.html","dijit/_WidgetBase","dijit/_TemplatedMixin","dijit/_FocusMixin","dijit/a11yclick","dijit/focus","../lang","../InfoTemplate","../kernel","../SpatialReference","../graphic","../promiseList","../symbols/PictureMarkerSymbol","../symbols/SimpleMarkerSymbol","../symbols/SimpleLineSymbol","../symbols/SimpleFillSymbol","../symbols/TextSymbol","../symbols/Font","../geometry/Point","../geometry/Extent","../geometry/normalizeUtils","../geometry/scaleUtils","../tasks/locator","../tasks/query","../Color","../styles/basic"],function(e,t,s,i,r,a,o,n,h,u,c,l,d,f,p,g,m,y,_,v,S,x,w,b,R,N,L,I,M,C,O,P,F,T,A,E,j,k,D,B,W,G,H,K){function V(e,t){e&&t&&(e._layer=t,e._sourceLayer=t)}function Q(e,t,s,i){var r,a;switch(s){case"point":r=new P,r.setColor(t),r.setSize(null!==i?i:e.size),a=new F,a.setColor(e.outline.color),a.setWidth(e.outline.width),r.setOutline(a);break;case"line":r=new F,r.setColor(t),r.setWidth(null!==i?i:e.width);break;case"polygon":r=new T,r.setColor(t),a=new F,a.setColor(e.outline.color),a.setWidth(e.outline.width),r.setOutline(a)}return r}var q=t([v,S,x,r],{declaredClass:"esri.dijit.Search",templateString:_,reHostedFS:/https?:\/\/services.*\.arcgis\.com/i,constructor:function(t,i){this.css={searchGroup:"searchGroup",searchInput:"searchInput",searchInputGroup:"searchInputGroup",searchBtn:"searchBtn",searchSubmit:"searchSubmit",searchIcon:"searchIcon esri-icon-search",searchButtonText:"searchButtonText",searchToggle:"searchToggle",searchToggleIcon:"searchIcon esri-icon-down-arrow",searchMenu:"searchMenu",searchMenuHeader:"menuHeader",searchClear:"searchClear",searchClearIcon:"searchIcon esri-icon-close searchClose",searchSpinner:"searchIcon esri-icon-loading-indicator searchSpinner",searchSourceName:"sourceName",suggestionsMenu:"suggestionsMenu",sourcesMenu:"sourcesMenu",activeSource:"active",hasValue:"hasValue",hasButtonMode:"hasButtonMode",hasMultipleSources:"hasMultipleSources",showSuggestions:"showSuggestions",showSources:"showSources",showNoResults:"showNoResults",searchLoading:"searchLoading",latLonHeader:"searchLatLongHeader",searchMoreResults:"moreResults",searchMoreResultsList:"resultsList",searchMoreResultsHeader:"moreHeader",searchMoreResultsItem:"moreItem",searchMoreResultsListHeader:"popupHeader",searchShowMoreResults:"showMoreResults",searchNoResultsMenu:"noResultsMenu",searchNoResultsBody:"noResultsBody",searchNoResultsHeader:"noResultsHeader",searchNoValueIcon:"noValueIcon esri-icon-notice-triangle",searchNoValueText:"noValueText",searchNoResultsText:"noResultsText",searchExpandContainer:"searchExpandContainer",searchAnimateContainer:"searchAnimate",searchExpanded:"searchExpanded",searchCollapsed:"searchCollapsed",searchClearFloat:"searchClearFloat"},this._allIndex="all",this._objectIdIdentifier="_objectId",this._deferreds=[],this._sourceNames=[],this.defaultSource={locator:new W("//geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer"),singleLineFieldName:"SingleLine",outFields:["Addr_type","Match_addr","StAddr","City"],name:y.widgets.Search.main.esriLocatorName,localSearchOptions:{minScale:3e5,distance:5e4},placeholder:y.widgets.Search.main.placeholder,highlightSymbol:new O(e.toUrl("./Search/images/search-pointer.png"),36,36).setOffset(9,18)},this.options={map:null,theme:"arcgisSearch",visible:!0,value:"",allPlaceholder:"",sources:[this.defaultSource],activeSourceIndex:0,suggestionDelay:150,enableSourcesMenu:!0,enableSuggestionsMenu:!0,enableInfoWindow:!0,showInfoWindowOnSelect:!0,enableSuggestions:!0,enableButtonMode:!1,autoNavigate:!0,autoSelect:!0,addLayersFromMap:!1,zoomScale:1e3,graphicsLayer:null,enableHighlight:!0,highlightGraphic:null,enableLabel:!1,labelSymbol:(new A).setColor(new H([181,56,46,.9])).setFont(new E("14px",E.STYLE_NORMAL,E.VARIANT_NORMAL,E.WEIGHT_BOLD,"Arial")),labelGraphic:null,infoTemplate:new N(y.widgets.Search.main.searchResult,'<div class="${searchTheme}"><div id="${searchMoreResultsId}" class="${searchMoreResults}"><div class="${searchMoreResultsItem}">${searchResult}</div><div>${searchMoreResultsHtml}</div></div></div>'),searchResults:null,suggestResults:null,selectedResult:null,magicKey:null,selectedFeatureId:null,expanded:!1,maxLength:128,maxResults:6,maxSuggestions:6,locationToAddressDistance:1500,minCharacters:1,enableSearchingAll:!0};var r=s.mixin({},this.options,t);this.set(r),this._updateActiveSource(),this._i18n=y,this._defaultSR=new I(4326),this.domNode=i},startup:function(){this.inherited(arguments),this.sources||(this.sources=[]),this._mapLoaded().then(s.hitch(this,this._init))},postCreate:function(){var e=this;this.inherited(arguments),this._moreResultsId=this.id+"_more_results",this.own(n(this.submitNode,w,s.hitch(this,this._searchButton))),this.own(n(this.sourcesBtnNode,w,s.hitch(this,this._toggleSourcesMenu))),this.own(n(this.inputNode,w,s.hitch(this,this._inputClick))),this.own(n(this.clearNode,w,s.hitch(this,this._clearButton))),this.own(n(this.formNode,"submit",s.hitch(this,function(e){e.preventDefault(),this._cancelSuggest(),this.search()}))),this.own(n(this.inputNode,"keyup",s.hitch(this,function(e){this._inputKey(e)}))),this.own(n(this.sourcesBtnNode,"keyup",s.hitch(this,function(e){this._sourceBtnKey(e)}))),this.own(n(this.suggestionsNode,"li:click, li:keyup",function(t){e._suggestionsEvent(t,this)})),this.own(n(this.sourcesNode,"li:click, li:keyup",function(t){e._sourcesEvent(t,this)})),this.own(n(this.inputNode,"input, paste",s.hitch(this,function(){this._suggestDelay()}))),this.map&&this.map.infoWindow&&this.map.infoWindow.domNode&&this.enableInfoWindow&&(this.own(n(this.map.infoWindow.domNode,"#"+this._moreResultsId+"_show:click",s.hitch(this,function(e){this._showMoreResultsClick(e)}))),this.own(n(this.map.infoWindow.domNode,"#"+this._moreResultsId+"_list li a:click",s.hitch(this,function(e){this._moreResultsClick(e)}))),this.own(n(this.map.infoWindow.domNode,"#"+this._moreResultsId+" [data-switch-coordinates]:click",s.hitch(this,function(e){this._switchCoordinatesClick(e)})))),this.value&&this._checkStatus(),this._hideMenus(),this._updateVisible(),this._insertSources(this.sources),this._setPlaceholder(this.activeSourceIndex),this._updateButtonMode(this.enableButtonMode),this.toggle(this.expanded)},destroy:function(){this.clear(),g.empty(this.domNode),this.inherited(arguments)},clear:function(){this.clearGraphics(),d.get(this.inputNode,"value")&&d.set(this.inputNode,"value",""),this._changeAttrValue("value",""),this.set("searchResults",null),this.set("suggestResults",null),this.set("selectedResult",null),this.set("magicKey",null),this.set("selectedFeatureId",null),f.remove(this.containerNode,this.css.hasValue),d.set(this.clearNode,"title",""),this._hideMenus(),this._closePopup(),this._hideLoading(),this.emit("clear-search")},show:function(){p.set(this.domNode,"display","block")},hide:function(){p.set(this.domNode,"display","none")},expand:function(){this.enableButtonMode&&(f.add(this.containerNode,this.css.searchExpanded),f.remove(this.containerNode,this.css.searchCollapsed),this._hideMenus(),this.set("expanded",!0))},collapse:function(){this.enableButtonMode&&(f.remove(this.containerNode,this.css.searchExpanded),f.add(this.containerNode,this.css.searchCollapsed),this._hideMenus(),this.set("expanded",!1))},toggle:function(e){this.enableButtonMode&&(void 0===e&&(e=!this.expanded),e?this.expand():this.collapse())},search:function(e){var t=new a;return this._mapLoaded().then(s.hitch(this,function(){this._searchDeferred(e).then(s.hitch(this,function(e){var s=e.results;this.set("searchResults",s),0===e.numResults&&(this._noResults(e.value),this._showNoResultsMenu()),this._hideLoading(),this.emit("search-results",e),this._selectFirstResult(s,e.activeSourceIndex),t.resolve(s)}),s.hitch(this,function(e){t.reject(e)}))})),t.promise},suggest:function(e){var t=new a;return this._mapLoaded().then(s.hitch(this,function(){this._suggestDeferred(e).then(s.hitch(this,function(e){if(e){var s=e.results;this.set("suggestResults",s),this._insertSuggestions(s,e.value),this.emit("suggest-results",e),t.resolve(s)}}),s.hitch(this,function(e){t.reject(e)}))})),t.promise},select:function(e){var t,i=this._getDefaultSymbol(e),r=this.labelSymbol,a=this.sources,o=this.activeSourceIndex,n=this.enableHighlight,h=this.enableLabel,u=this.autoNavigate,c=this.showInfoWindowOnSelect,l=this.enableInfoWindow,d=this.infoTemplate,f=e.feature?new M(e.feature.toJson()):null,p=f?e.feature._sourceLayer:null;if(V(f,p),o===this._allIndex){var g=this._getSourceIndexOfResult(e);null!==g&&(t=a[g],o=g)}else t=a[o];if(t&&(t.hasOwnProperty("highlightSymbol")&&(i=t.highlightSymbol),t.hasOwnProperty("labelSymbol")&&(r=t.labelSymbol),t.hasOwnProperty("enableHighlight")&&(n=t.enableHighlight),t.hasOwnProperty("enableLabel")&&(h=t.enableLabel),t.hasOwnProperty("autoNavigate")&&(u=t.autoNavigate),t.hasOwnProperty("showInfoWindowOnSelect")&&(c=t.showInfoWindowOnSelect),t.hasOwnProperty("enableInfoWindow")&&(l=t.enableInfoWindow),t.hasOwnProperty("infoTemplate")?d=t.infoTemplate:t.featureLayer&&t.featureLayer.infoTemplate&&(d=t.featureLayer.infoTemplate)),this._hideMenus(),this._hideLoading(),f){var m=this.highlightGraphic,y=this.graphicsLayer,_=this.labelGraphic,v=s.mixin({},f.attributes,{searchTheme:this.theme,searchResult:this._searchResultHTML(e),searchMoreResults:this.css.searchMoreResults,searchMoreResultsItem:this.css.searchMoreResultsItem,searchMoreResultsId:this._moreResultsId,searchMoreResultsHtml:this._moreResultsHTML(e)}),S=null;if(l&&(S=d),_?(_.setGeometry(f.geometry),_.setAttributes(v),_.setSymbol(r),r&&"textsymbol"===r.type&&_.symbol.setText(e.name)):(_=new M(f.geometry,r,v),V(_,p),r&&"textsymbol"===r.type&&_.symbol.setText(e.name),h&&(y?y.add(_):this.map&&this.map.graphics&&this.map.graphics.add(_))),m?(m.setGeometry(f.geometry),m.setAttributes(v),m.setInfoTemplate(S),m.setSymbol(i)):(m=new M(f.geometry,i,v,S),V(m,p),n&&(y?y.add(m):this.map&&this.map.graphics&&this.map.graphics.add(m))),m&&m.symbol&&"textsymbol"===m.symbol.type&&m.symbol.setText(e.name),this.map&&this.map.infoWindow&&l&&c){this.map.infoWindow.setFeatures([m]);var x=this._getPointFromGeometry(m.geometry);this.map.infoWindow.show(x)}this.map&&u&&e&&e.hasOwnProperty("extent")&&"function"==typeof this.map.setExtent&&this.map.setExtent(e.extent,!0),this.set("highlightGraphic",m),this.set("labelGraphic",_)}this.set("selectedResult",e),this.emit("select-result",{result:e,source:t,sourceIndex:o})},focus:function(){b.focus(this.inputNode)},blur:function(){this.inputNode.blur(),b.curNode&&b.curNode.blur()},clearGraphics:function(){var e=this.highlightGraphic,t=this.graphicsLayer,s=this.labelGraphic;e&&(t?t.remove(e):this.map&&this.map.graphics&&this.map.graphics.remove(e)),s&&(t?t.remove(s):this.map&&this.map.graphics&&this.map.graphics.remove(s)),this.set("labelGraphic",null),this.set("highlightGraphic",null)},_mapLoaded:function(){var e=new a;return this.map?this.map.loaded?e.resolve():n.once(this.map,"load",s.hitch(this,function(){e.resolve()})):e.resolve(),e.promise},_init:function(){this._getMapLayers().then(s.hitch(this,function(){this.set("loaded",!0),this.emit("load")}))},_clearButton:function(){this.clear(),b.focus(this.inputNode)},_error:function(e){return new Error(this.declaredClass+" "+e)},_searchDeferred:function(e){var t,i=new a,r=this.value,o=this.activeSourceIndex;e&&e.hasOwnProperty("index")&&(o=e.index),this._showLoading(),this._hideMenus(),this._closePopup(),this.clearGraphics();var n={magicKey:this.magicKey,text:r};return e?"string"==typeof e?(n.text=e,t=this._searchQueries(n)):t="object"==typeof e&&e.hasOwnProperty("magicKey")?this._searchQueries(e):"object"==typeof e&&e.hasOwnProperty("geometry")?this._searchQueries({geometry:e}):"object"==typeof e&&e.hasOwnProperty(this._objectIdIdentifier)?this._searchQueries(e):"object"==typeof e&&"point"===e.type?this._searchQueries({point:e}):e instanceof Array&&2===e.length?this._searchQueries({latlon:e}):this._searchQueries(n):t=this._searchQueries(n),t.always(s.hitch(this,function(e){var t=this._formatResults(e,o,r);i.resolve(t)})),i.promise},_suggestDeferred:function(e){var t,i=new a;this._deferreds.push(i),e||(e=this.value);var r=this.activeSourceIndex;return t=this._suggestQueries({text:e}),t.always(s.hitch(this,function(t){var s;if(t)for(var a=0;a<t.length;a++)t[a]&&(s=!0);if(s){var o=this._formatResults(t,r,e);i.resolve(o)}else i.resolve()})),i.promise},_getDefaultSymbol:function(e){var t,s,i,r,a;return this.map&&(a=this.map.getBasemap()),a||(a="topo"),e&&e.feature&&e.feature.geometry&&(r=e.feature.geometry.type),"polyline"===r?r="line":"circle"===r||"extent"===r?r="polygon":"multipoint"===r&&(r="point"),r&&(s=K.getSchemes({theme:"default",basemap:a,geometryType:r}),s&&(i=s.primaryScheme),i&&(i.color&&i.hasOwnProperty("opacity")&&(i.color.a=i.opacity),t=Q(i,i.color,r,i.size))),t},_selectFirstResult:function(e,t){if(this.autoSelect&&e){var s;t===this._allIndex?s=this._getFirstResult(e):e[t]&&e[t][0]&&(s=e[t][0]),s&&this.select(s)}},_getSourceIndexOfResult:function(e){var t=this.searchResults;if(t)for(var s in t)if(t[s]&&t[s].length)for(var i=0;i<t[s].length;i++)if(t[s][i]===e)return parseInt(s,10);return null},_getFirstResult:function(e){if(e)for(var t in e)if(e[t]&&e[t][0])return e[t][0];return!1},_onFocus:function(){this.map&&"function"==typeof this.map.disableKeyboardNavigation&&this.map.disableKeyboardNavigation(),this.emit("focus"),this.inherited(arguments)},_onBlur:function(){this._hideMenus(),this.map&&"function"==typeof this.map.enableKeyboardNavigation&&this.map.enableKeyboardNavigation(),this.enableButtonMode&&this.loaded&&this.collapse(),this.emit("blur"),this.inherited(arguments)},_getMapLayers:function(){var e=new a;if(this.addLayersFromMap&&this.map){var t=[],i=this.map.graphicsLayerIds;if(i&&i.length){for(var r=0;r<i.length;r++){var o=this.map.getLayer(i[r]);o&&t.push(this._featureLayerLoaded(o))}C(t).always(s.hitch(this,function(t){for(var s,i=t,r=this.sources,a=0;a<i.length;a++)i[a]&&i[a].loaded&&"Feature Layer"===i[a].type&&(r.push({featureLayer:i[a],enableSuggestions:!0}),s=!0);s&&this.set("sources",r),e.resolve()}))}else e.resolve()}else e.resolve();return e.promise},_switchCoordinatesClick:function(e){e.preventDefault();var t=e.target,s=d.get(t,"data-switch-coordinates");s&&(this._cancelSuggest(),this.set("value",s),this.search())},_moreResultsClick:function(e){e.preventDefault();var t=e.target,s=parseInt(d.get(t,"data-source-index"),10),i=parseInt(d.get(t,"data-index"),10),r=this.searchResults;if(r&&r[s]){var a=r[s][i];a&&this.select(a)}},_showMoreResultsClick:function(e){e.preventDefault();var t=l.byId(this._moreResultsId);if(t){f.toggle(t,this.css.searchShowMoreResults);var s=l.byId(this._moreResultsId+"_show");s&&(f.contains(t,this.css.searchShowMoreResults)?d.set(s,"textContent",y.widgets.Search.main.hideMoreResults):d.set(s,"textContent",y.widgets.Search.main.showMoreResults))}},_featureLayerLoaded:function(e){var t=new a;if(e.loaded)t.resolve(e);else if(e.loadError)t.reject(this._error("Layer failed to load."));else{var i,r;i=n.once(e,"load",s.hitch(this,function(){r.remove(),t.resolve(e)})),r=n.once(e,"error",s.hitch(this,function(){i.remove(),t.reject(this._error("Layer could not be loaded."))}))}return t.promise},_getObjectSize:function(e){var t,s=0;for(t in e)e.hasOwnProperty(t)&&s++;return s},_sourcesEvent:function(e,t){var s=d.get(t,"data-index"),r=h("li",this.sourcesNode),a=i.indexOf(r,t);s!==this._allIndex&&(s=parseInt(s,10));var n;"click"===e.type||e.keyCode===o.ENTER?(this.set("activeSourceIndex",s),b.focus(this.inputNode),this._hideSourcesMenu()):e.keyCode===o.UP_ARROW?(e.stopPropagation(),e.preventDefault(),n=a-1,n<0?b.focus(this.sourcesBtnNode):b.focus(r[n])):e.keyCode===o.DOWN_ARROW?(e.stopPropagation(),e.preventDefault(),n=a+1,n>=r.length?b.focus(this.sourcesBtnNode):b.focus(r[n])):e.keyCode===o.ESCAPE&&(this._hideSourcesMenu(),b.focus(this.inputNode))},_suggestionsEvent:function(e,t){var s=d.get(t,"data-source-index"),r=parseInt(d.get(t,"data-index"),10),a=h("li",this.suggestionsNode),n=this.sources,u=i.indexOf(a,t);s!==this._allIndex&&(s=parseInt(s,10));var c;if(this._clearQueryTimeout(),"click"===e.type||e.keyCode===o.ENTER){var l,f=this.suggestResults;if(f&&f[s]&&f[s][r]&&(l=f[s][r]),l){if(l.index=s,n[s].featureLayer){var p=n[s].featureLayer.objectIdField;l[this._objectIdIdentifier]=l.feature.attributes[p],this.set("value",this._getSuggestionName(l)),this.set("selectedFeatureId",l.feature.attributes[p])}else l.magicKey&&l.text&&(this.set("value",l.text),this.set("magicKey",l.magicKey));this.search(l),b.focus(this.inputNode)}}else e.keyCode===o.BACKSPACE||e.keyCode===o.DELETE?b.focus(this.inputNode):e.keyCode===o.UP_ARROW?(e.stopPropagation(),e.preventDefault(),c=u-1,c<0?b.focus(this.inputNode):b.focus(a[c])):e.keyCode===o.DOWN_ARROW?(e.stopPropagation(),e.preventDefault(),c=u+1,c>=a.length?b.focus(this.inputNode):b.focus(a[c])):e.keyCode===o.ESCAPE&&(this._hideMenus(),b.focus(this.inputNode))},_getResultName:function(e){var t;return e.hasOwnProperty("name")&&null!==e.name&&(t=e.name.toString()),t||(t=y.widgets.Search.main.untitledResult),t},_getSuggestionName:function(e){var t,s;return e.hasOwnProperty("name")&&null!==e.name&&(s=e.name.toString()),t=e.text||s,t||(t=y.widgets.Search.main.untitledResult),t},_searchResultHTML:function(e){var t="";if(e.feature&&e.feature.attributes&&e.feature.attributes.Addr_type&&"LatLong"===e.feature.attributes.Addr_type){var s,i,r=e.name.split(" ");if(2===r.length&&(s=r[0],i=r[1]),i&&s){var a=parseFloat(s),o=parseFloat(i),n=a+", "+o,h=o+", "+a;t+='<div class="'+this.css.searchMoreResultsItem+'">',t+='<div class="'+this.css.latLonHeader+'">'+y.widgets.Search.main.lonlat+"</div>",t+=n,t+="</div>",t+='<div class="'+this.css.searchMoreResultsItem+'">',a===o||a>90||a<-90||o>180||o<-180||(t+='<div class="'+this.css.latLonHeader+'">'+y.widgets.Search.main.reverseLonLatHeader+"</div>",t+='<a data-switch-coordinates="'+h+'" tabindex="0" href="#">'+h+"</a>",t+="</div>")}else t=e.name}else t=e.name;return t},_moreResultsHTML:function(e){var t="",s="",i=this.searchResults,r=this.sources,a=0;if(i){s+='<div class="'+this.css.searchMoreResultsItem+'">',s+='<a href="#" id="'+this._moreResultsId+'_show">'+y.widgets.Search.main.showMoreResults+"</a>",s+="</div>",s+='<div class="'+this.css.searchMoreResultsList+'">',s+='<div id="'+this._moreResultsId+'_list">';for(var o in i)if(i[o]){var n=i[o].length;if(n){var h=1===n&&i[o][0]===e;if(this._getObjectSize(i)>1&&!h){var u=this._getSourceName(o);s+='<div class="'+this.css.searchMoreResultsListHeader+'">'+u+"</div>"}if(n&&!h){s+="<ul>";var c,l=r[o].maxResults||this.maxResults;for(c=0;c<n&&c<l;++c)if(i[o][c]!==e){var d=this._getResultName(i[o][c]);s+='<li><a tabindex="0" data-index="'+c+'" data-source-index="'+o+'" href="#">'+d+"</a></li>",a++}s+="</ul>"}}}s+="</div>",s+="</div>"}return a&&(t+=s),t},_validField:function(e,t){return e.getField(t)},_validFields:function(e,t){if(e&&t&&t.length){for(var s=0;s<t.length;s++){if(!this._validField(e,t[s]))return!1}return!0}return!1},_getCodedName:function(e,t){if(e&&e.length)for(var s=0,i=e.length;s<i;s++){var r=e[s];if(r.code===t)return r.name}},_getCodedValue:function(e,t,s){if(e&&e.length)for(var i=0,r=e.length;i<r;i++){var a=e[i],o=a.name,n=t;if(s||(o=o.toLowerCase(),n=n.toLowerCase()),o===n)return a.code}return!1},_whereClause:function(e,t,s,i){var r=null;if(e){var a="";if(this.reHostedFS.test(t.url)&&this._containsNonLatinCharacter(e)&&(a="N"),s&&s.length)for(var o=0,n=s.length;o<n;o++){var h="",u=e.replace(/\'/g,"''"),c=s[o],l=t.getField(c),d=t.getDomain(c);if(d&&"codedValue"===d.type&&(u=this._getCodedValue(d.codedValues,u,i)),!1!==u){var f=l.type;if("esriFieldTypeString"===f||"esriFieldTypeDate"===f)h=i?c+" = "+a+"'"+u+"'":"UPPER("+c+") LIKE "+a+"'%"+u.toUpperCase()+"%'";else if("esriFieldTypeOID"===f||"esriFieldTypeSmallInteger"===f||"esriFieldTypeInteger"===f||"esriFieldTypeSingle"===f||"esriFieldTypeDouble"===f){var p=parseFloat(u);h=!isNaN(p)&&c+" = "+p}else h=c+" = "+u;h&&(r?r+=" or ":r="",r+=h)}}}return r},_suggest:function(e){e||(e={index:this.activeSourceIndex,text:this.value});var t=new a,r=this.sources,o=e.index,n=r[o],h=this.enableSuggestions;n.hasOwnProperty("enableSuggestions")&&(h=n.enableSuggestions);var u,c=0;e.hasOwnProperty("text")&&e.text&&(u=s.trim(e.text),c=e.text.length);var l=n.minCharacters||this.minCharacters;if(h&&u&&c>=l&&this._supportsPagination(n)){var d="";n.prefix&&(d+=n.prefix),d+=u,n.suffix&&(d+=n.suffix);var f=this._defaultSR;this.map&&(f=this.map.spatialReference);var p={};if(n.locator){if(n.categories&&(p.categories=n.categories),n.locator.outSpatialReference=f,this.map&&n.localSearchOptions&&n.localSearchOptions.hasOwnProperty("distance")&&n.localSearchOptions.hasOwnProperty("minScale")){var g=this._getScale();(!n.localSearchOptions.minScale||g&&g<=parseFloat(n.localSearchOptions.minScale))&&(p.location=this.map.extent.getCenter(),p.distance=n.localSearchOptions.distance)}p.text=d,n.useMapExtent&&this.map&&this.map.extent&&(p.searchExtent=this.map.extent),n.searchExtent&&(p.searchExtent=n.searchExtent),p.maxSuggestions=n.maxSuggestions||this.maxSuggestions,n.sourceCountry&&(p.countryCode=n.sourceCountry),n.countryCode&&(p.countryCode=n.countryCode),n.locator.suggestLocations(p).then(s.hitch(this,function(e){t.resolve(e)}),s.hitch(this,function(e){e||(e=this._error("Locator suggestLocations could not be performed.")),t.reject(e)}))}else n.featureLayer?this._featureLayerLoaded(n.featureLayer).then(s.hitch(this,function(){var e=this._getDisplayField(n),r=n.searchFields||[e],a=[];n.suggestionTemplate?n.suggestionTemplate.replace(/(?:\$\{([^}]+)\})/g,function(){var e=arguments[1];a.push(e)}):a=[e],-1===i.indexOf(a,n.featureLayer.objectIdField)&&a.push(n.featureLayer.objectIdField);var h=this._validField(n.featureLayer,e),u=this._validFields(n.featureLayer,a),c=this._validFields(n.featureLayer,r);if(h&&u&&c){var l=new G;n.hasOwnProperty("suggestQueryParams")&&s.mixin(l,n.suggestQueryParams),l.outSpatialReference=f,l.returnGeometry=!1,l.num=n.maxSuggestions||this.maxSuggestions,l.outFields=a,n.useMapExtent&&this.map&&this.map.extent&&(l.geometry=this.map.extent),n.searchExtent&&(l.geometry=n.searchExtent);var p,g=this._whereClause(d,n.featureLayer,r,!1);g&&(l.where=g,p=!0),p?n.featureLayer.queryFeatures(l,s.hitch(this,function(e){var s,i=e.features;i&&(s=this._hydrateResults(i,o,!0)),t.resolve(s)}),s.hitch(this,function(e){e||(e=this._error("FeatureLayer queryFeatures errored with suggestions")),t.reject(e)})):t.resolve()}else t.reject(this._error("Invalid FeatureLayer field"))})):t.reject(this._error("Invalid source"))}else t.resolve();return t.promise},_supportsPagination:function(e){var t;return e.locator?t=!0:e.featureLayer&&e.featureLayer.advancedQueryCapabilities&&e.featureLayer.advancedQueryCapabilities.supportsPagination&&(t=!0),t},_suggestQueries:function(e){var t,s=this.sources,i=this.activeSourceIndex,r=[];if(i===this._allIndex)for(var a=0;a<s.length;a++){var o=e;o.index=a,t=this._suggest(o),r.push(t)}else{var n=e;n.index=i,t=this._suggest(n),r.push(t)}return C(r)},_getPointFromGeometry:function(e){var t;switch(e.type){case"extent":t=e.getCenter();break;case"multipoint":t=e.getPoint(0);break;case"point":t=e;break;case"polygon":t=e.getCentroid();break;case"polyline":t=e.getPoint(0,0)}return t},_searchQueries:function(e){e.hasOwnProperty("index")||(e.index=this.activeSourceIndex);var t,s=[];if(e.index===this._allIndex)for(var i=this.sources,r=0;r<i.length;r++){var a=e;a.index=r,t=this._search(a),s.push(t)}else{var o=this._search(e);s.push(o)}return C(s)},_searchButton:function(){this.enableButtonMode&&!this.expanded?(this.expand(),b.focus(this.inputNode)):(this._cancelSuggest(),this.search())},_search:function(e){e||(e={text:this.value,magicKey:null,geometry:null,point:null,index:this.activeSourceIndex,latlon:null}),this.selectedFeatureId&&(e.text=null,e[this._objectIdIdentifier]=this.selectedFeatureId);var t,i,r=new a,o=e.index,n=this.sources[o];if(e.hasOwnProperty("text")&&e.text&&(i=s.trim(e.text)),n){var h="";n.prefix&&!e.magicKey&&(h+=n.prefix),h+=i,n.suffix&&!e.magicKey&&(h+=n.suffix);var u=this._defaultSR;if(this.map&&(u=this.map.spatialReference),n.locator)if(e.hasOwnProperty("text")&&i){var c={};if(n.categories&&(c.categories=n.categories),n.locationType&&(c.locationType=n.locationType),u&&(n.locator.outSpatialReference=u),this.map&&n.localSearchOptions&&n.localSearchOptions.hasOwnProperty("distance")&&n.localSearchOptions.hasOwnProperty("minScale")){var l=this._getScale();(!n.localSearchOptions.minScale||l&&l<=parseFloat(n.localSearchOptions.minScale))&&(c.location=this.map.extent.getCenter(),c.distance=n.localSearchOptions.distance)}c.address={},c.maxLocations=n.maxResults||this.maxResults,n.useMapExtent&&this.map&&this.map.extent&&(c.searchExtent=this.map.extent),n.searchExtent&&(c.searchExtent=n.searchExtent),n.sourceCountry&&(c.countryCode=n.sourceCountry),n.countryCode&&(c.countryCode=n.countryCode),e.magicKey&&(c.magicKey=e.magicKey),n.singleLineFieldName?c.address[n.singleLineFieldName]=h:c.address["Single Line Input"]=h,n.outFields&&(c.outFields=n.outFields),n.locator.addressToLocations(c).then(s.hitch(this,function(e){var t=this._hydrateResults(e,o,!1);r.resolve(t)}),s.hitch(this,function(e){e||(e=this._error("Locator addressToLocations could not be performed")),r.reject(e)}))}else if(e.geometry)t=this._getPointFromGeometry(e.geometry.geometry),t?this._reverseGeocodePoint(o,t).then(function(e){r.resolve(e)},function(e){r.reject(e)}):r.reject(this._error("Invalid point to reverse geocode"));else if(e.point)this._reverseGeocodePoint(o,e.point).then(function(e){r.resolve(e)},function(e){r.reject(e)});else if(e.latlon){var d=new j(e.latlon,this._defaultSR);this._reverseGeocodePoint(o,d).then(function(e){r.resolve(e)},function(e){r.reject(e)})}else e.hasOwnProperty("text")&&!i?r.resolve([]):r.reject(this._error("Invalid query type for Locator"));else n.featureLayer?this._featureLayerLoaded(n.featureLayer).then(s.hitch(this,function(){var a=this._getDisplayField(n),c=n.searchFields||[a],l=this._validField(n.featureLayer,a),d=this._validFields(n.featureLayer,c);if(l&&d){var f=new G;if(n.hasOwnProperty("searchQueryParams")&&s.mixin(f,n.searchQueryParams),u){f.outSpatialReference=u;var p=this.map&&this.map.getMaxResolution(),g=p||1/B.getUnitValueForSR(u);g&&(f.maxAllowableOffset=g)}f.returnGeometry=!0,n.outFields&&(f.outFields=n.outFields);var m;e.hasOwnProperty(this._objectIdIdentifier)||(this._supportsPagination(n)&&(f.num=n.maxResults||this.maxResults),n.useMapExtent&&this.map&&this.map.extent&&(f.geometry=this.map.extent),n.searchExtent&&(f.geometry=n.searchExtent),m=n.exactMatch);var y;if(e.hasOwnProperty("text")&&i){var _=this._whereClause(h,n.featureLayer,c,m);_?(f.where=_,y=!0):y=!1}else e.hasOwnProperty(this._objectIdIdentifier)?(f.objectIds=[e[this._objectIdIdentifier]],y=!0):e.geometry?(f.geometry=e.geometry,y=!0):e.point?(f.geometry=e.point,y=!0):e.latlon?(t=new j(e.latlon,this._defaultSR),f.geometry=t,y=!0):e.hasOwnProperty("text")&&!i?(r.resolve([]),y=!1):(r.reject(this._error("Invalid query type for FeatureLayer")),y=!1);y?n.featureLayer.queryFeatures(f,s.hitch(this,function(e){var t,s=e.features;s&&(t=this._hydrateResults(s,o,!1)),r.resolve(t)}),s.hitch(this,function(e){e||(e=this._error("FeatureLayer queryFeatures could not be performed")),r.reject(e)})):r.resolve()}else r.reject(this._error("Invalid FeatureLayer field"))})):r.reject(this._error("Invalid source"))}else r.reject(this._error("Source is undefined"));return r.promise},_clearQueryTimeout:function(){this._queryTimer&&clearTimeout(this._queryTimer)},_formatResults:function(e,t,s){var i={activeSourceIndex:t,value:s,numResults:0,numErrors:0,errors:null,results:null},r={},a={};if(e)if(t===this._allIndex)for(var o=0;o<e.length;o++)e[o]&&(e[o]instanceof Error?(r[o]=e[o],i.numErrors++):(a[o]=e[o],i.numResults+=e[o].length));else e[0]&&(e[0]instanceof Error?(r[t]=e[0],i.numErrors++):(a[t]=e[0],i.numResults+=e[0].length));return i.numErrors&&(i.errors=r),i.numResults&&(i.results=a),i},_reverseGeocodePoint:function(e,t){var i=new a,r=this.sources,o=r[e];if(t&&o){var n=o.locationToAddressDistance||this.locationToAddressDistance;o.locator.outSpatialReference=this._defaultSR,this.map&&(o.locator.outSpatialReference=this.map.spatialReference),o.locator.locationToAddress(t,n,s.hitch(this,function(t){var s=this._hydrateResults([t],e,!1);i.resolve(s)}),s.hitch(this,function(e){e||(e=this._error("Locator locationToAddress could not be performed")),i.reject(e)}))}else i.reject(this._error("No point or source defined for reverse geocoding"));return i.promise},_cancelDeferreds:function(){if(this._deferreds&&this._deferreds.length)for(var e=0;e<this._deferreds.length;e++)this._deferreds[e].cancel(this.declaredClass+" cancelling request");this._deferreds=[]},_sourceBtnKey:function(e){if(e){var t=h("li",this.sourcesNode);if(e.keyCode===o.UP_ARROW){e.stopPropagation(),e.preventDefault(),this._showSourcesMenu();var s=t.length;s&&b.focus(t[s-1])}else e.keyCode===o.DOWN_ARROW&&(e.stopPropagation(),e.preventDefault(),this._showSourcesMenu(),t[0]&&b.focus(t[0]))}},_inputKey:function(e){if(e){var t=h("li",this.suggestionsNode),s=this.suggestResults;if(e.keyCode===o.TAB||e.keyCode===o.ESCAPE)this._cancelSuggest(),this._hideMenus();else if(e.keyCode===o.UP_ARROW){e.stopPropagation(),e.preventDefault(),this._cancelSuggest(),s&&this._showSuggestionsMenu();var i=t.length;i&&b.focus(t[i-1])}else if(e.keyCode===o.DOWN_ARROW)e.stopPropagation(),e.preventDefault(),this._cancelSuggest(),s&&this._showSuggestionsMenu(),t[0]&&b.focus(t[0]);else{if(e.ctrlKey||e.metaKey||e.keyCode===o.copyKey||e.keyCode===o.LEFT_ARROW||e.keyCode===o.RIGHT_ARROW||e.keyCode===o.ENTER)return e;this._suggestDelay()}}},_cancelSuggest:function(){this._cancelDeferreds(),this._clearQueryTimeout()},_suggestDelay:function(){this._cancelSuggest(),this._changeValue(),this._queryTimer=setTimeout(s.hitch(this,function(){this.suggest()}),this.suggestionDelay)},_changeValue:function(){this.set("magicKey",null),this.set("selectedFeatureId",null),this._changeAttrValue("value",this.inputNode.value),this._checkStatus()},_inputClick:function(){this._hideSourcesMenu(),this._hideNoResultsMenu()},_getSourceName:function(e){return this._sourceNames[e]},_loadSources:function(e){var t=i.filter(e,function(e){return!!e.featureLayer}),s=i.map(t,function(e){return this._featureLayerLoaded(e.featureLayer)},this);return C(s)},_createSourceNameMap:function(e){return this._loadSources(e).then(s.hitch(this,function(){var t=i.map(e,function(e){return e.name||e.featureLayer&&e.featureLayer.name||y.widgets.Search.main.untitledSource});return this._preventDuplicateSourceNames(e,t),t}))},_getDuplicateSourceNameIndexes:function(e){var t={},s=[];return i.forEach(e,function(i,r){t.hasOwnProperty(i)?(-1===s.indexOf(t[i])&&s.push(t[i]),s.push(r)):e.lastIndexOf(i)!==r&&(t[i]=r)}),s},_preventDuplicateSourceNames:function(e,t){if(t&&t.length>1){var s=this._getDuplicateSourceNameIndexes(t);i.forEach(s,function(s){t[s]+=this._getFieldsString(e[s])},this)}},_getFieldsString:function(e){var t="",s=e.featureLayer;if(s)for(var i=e.searchFields||[this._getDisplayField(e)],r=0;r<i.length;r++){t+=0===r?": ":", ";var a=i[r],o=s.getFieldLabel(a);t+=o||a}return t},_splitResult:function(e,t){var s=c.escapeString(t);return e.replace(new RegExp("(^|)("+s+")(|$)","ig"),"$1|$2|$3").split("|")},_insertSuggestions:function(e,t){if(this.enableSuggestionsMenu&&this.suggestionsNode){this._hideSourcesMenu(),this._hideNoResultsMenu();var s,i=this.sources;if(e){s=g.create("div");for(var r in e)if(e[r]&&e[r].length){var a=this._getSourceName(r)
;i.length>1&&this.activeSourceIndex===this._allIndex&&g.create("div",{className:this.css.searchMenuHeader,textContent:a},s);for(var o=g.create("ul",{role:"menu"},s),n=i[r].maxSuggestions||this.maxSuggestions,h=0;h<e[r].length&&h<n;++h)for(var u=g.create("li",{"data-index":h,"data-source-index":r,role:"menuitem",tabindex:0},o),c=this._getSuggestionName(e[r][h]),l=this._splitResult(c,t),d=l.length,f=0;f<d;f++){var p=l[f];if(p.toLowerCase()===t.toLowerCase())g.create("strong",{textContent:p},u);else{var m=document.createTextNode(p);g.place(m,u)}}}}s?(g.place(s,this.suggestionsNode,"only"),this._showSuggestionsMenu()):(g.empty(this.suggestionsNode),this._hideSuggestionsMenu())}},_insertSources:function(e){if(this.enableSourcesMenu&&e&&e.length>1){var t,s,i=this.activeSourceIndex,r=g.create("ul",{role:"menu"});if(this.enableSearchingAll){var a="";i===this._allIndex&&(a="active"),g.create("li",{"data-index":this._allIndex,role:"menuitem",className:a,tabIndex:0,textContent:y.widgets.Search.main.all},r)}for(s=0;s<e.length;s++){t="",s===i&&(t=this.css.activeSource);var o=this._getSourceName(s);g.create("li",{"data-index":s,role:"menuitem",className:t,tabIndex:0,textContent:o},r)}f.add(this.containerNode,this.css.hasMultipleSources),g.place(r,this.sourcesNode,"only")}else f.remove(this.containerNode,this.css.hasMultipleSources),g.empty(this.sourcesNode)},_showLoading:function(){f.add(this.containerNode,this.css.searchLoading)},_hideLoading:function(){f.remove(this.containerNode,this.css.searchLoading)},_checkStatus:function(){this.value?(f.add(this.containerNode,this.css.hasValue),d.set(this.clearNode,"title",y.widgets.Search.main.clearButtonTitle)):this.clear()},_closePopup:function(){this.enableInfoWindow&&this.map&&this.map.infoWindow&&this.map.infoWindow.hide()},_noResults:function(e){var t;e&&(t=s.trim(e));var i=g.create("div",{className:this.css.searchNoResultsBody});if(e&&t)g.create("div",{className:this.css.searchNoResultsHeader,textContent:y.widgets.Search.main.noResults},i),g.create("div",{className:this.css.searchNoResultsText,textContent:R.substitute({value:'"'+e+'"'},y.widgets.Search.main.noResultsFound)},i);else{var r=g.create("div",{},i);g.create("span",{"aria-hidden":"true",className:this.css.searchNoValueIcon},r),g.create("span",{className:this.css.searchNoValueText,textContent:y.widgets.Search.main.emptyValue},r)}g.place(i,this.noResultsMenuNode,"only")},_hideMenus:function(){this._hideSourcesMenu(),this._hideSuggestionsMenu(),this._hideNoResultsMenu()},_hideNoResultsMenu:function(){f.remove(this.containerNode,this.css.showNoResults)},_showNoResultsMenu:function(){this._hideSourcesMenu(),this._hideSuggestionsMenu(),f.add(this.containerNode,this.css.showNoResults)},_hideSourcesMenu:function(){f.remove(this.containerNode,this.css.showSources)},_hideSuggestionsMenu:function(){f.remove(this.containerNode,this.css.showSuggestions)},_showSourcesMenu:function(){this._hideSuggestionsMenu(),this._hideNoResultsMenu(),f.add(this.containerNode,this.css.showSources)},_showSuggestionsMenu:function(){this._hideSourcesMenu(),this._hideNoResultsMenu(),f.add(this.containerNode,this.css.showSuggestions)},_toggleSourcesMenu:function(){this._hideSuggestionsMenu(),this._hideNoResultsMenu(),f.toggle(this.containerNode,this.css.showSources)},_getFirstStringField:function(e){if(e){var t=e.fields;if(t&&t.length)for(var s=0;s<t.length;s++){var i=t[s];if("esriFieldTypeString"===i.type)return i.name}}return""},_getDisplayField:function(e){return e.displayField||e.featureLayer.displayField||this._getFirstStringField(e.featureLayer)},_validLocation:function(e){return e&&"number"==typeof e.x&&"number"==typeof e.y},_validExtent:function(e){return e&&"number"==typeof e.xmin&&"number"==typeof e.ymin&&"number"==typeof e.xmax&&"number"==typeof e.ymax},_hydrateResult:function(e,t,i){var r,a,o={},n=this._defaultSR,h=this.sources,u=h[t];if(this.map&&(n=this.map.spatialReference),e.hasOwnProperty("text")&&e.hasOwnProperty("magicKey"))return e;if(e.hasOwnProperty("geometry")){var c=new M(e.toJson());o.feature=c,a=o.feature.geometry,a&&a.setSpatialReference(n)}else if(e.hasOwnProperty("location")&&this._validLocation(e.location)){var l=new j(e.location.x,e.location.y,n);r={},e.hasOwnProperty("attributes")&&(r=e.attributes),e.hasOwnProperty("address")&&"object"==typeof e.address&&s.mixin(r,e.address),e.hasOwnProperty("score")&&(r.score=e.score),o.feature=new M(l,null,r,null)}if(!o.feature&&i&&(r={},e.hasOwnProperty("attributes")&&(r=e.attributes),e.hasOwnProperty("score")&&(r.score=e.score),o.feature=new M(null,null,r,null)),o.feature){if(e.hasOwnProperty("extent")&&this._validExtent(e.extent))o.extent=new k(e.extent),o.extent.setSpatialReference(n);else if(o.feature&&o.feature.geometry)switch(o.feature.geometry.type){case"extent":o.extent=o.feature.geometry;break;case"multipoint":case"polygon":case"polyline":o.extent=D.getDenormalizedExtent(o.feature.geometry);break;case"point":if(this.map){var d=this.zoomScale;u&&u.zoomScale&&(d=u.zoomScale),this._getScale()>d?o.extent=B.getExtentForScale(this.map,d).centerAt(o.feature.geometry):o.extent=this.map.extent.centerAt(o.feature.geometry)}else o.extent=new k({xmin:o.feature.geometry.x-.25,ymin:o.feature.geometry.y-.25,xmax:o.feature.geometry.x+.25,ymax:o.feature.geometry.y+.25,spatialReference:this._defaultSR})}else o.extent=null;if(o.name="",u.featureLayer)if(u.suggestionTemplate&&i)o.name=R.substitute(e.attributes,u.suggestionTemplate);else if(u.searchTemplate)o.name=R.substitute(e.attributes,u.searchTemplate);else{var f=this._getDisplayField(u),p=u.featureLayer.getField(f),g=u.featureLayer.getDomain(f);if(f&&e.hasOwnProperty("attributes")&&e.attributes.hasOwnProperty(f)){var y=e.attributes[f];g&&"codedValue"===g.type?o.name=this._getCodedName(g.codedValues,y):p&&"esriFieldTypeDate"===p.type&&!isNaN(y)?o.name=m.format(new Date(y)):o.name=y}}else e.address&&u.searchTemplate?o.name=R.substitute(e.address,u.searchTemplate):e.hasOwnProperty("name")?o.name=e.name:e.hasOwnProperty("attributes")&&"object"==typeof e.attributes&&e.attributes.LongLabel?o.name=e.attributes.LongLabel:e.hasOwnProperty("attributes")&&"object"==typeof e.attributes&&e.attributes.Match_addr?(o.name=e.attributes.Match_addr,e.attributes.Addr_type&&"POI"===e.attributes.Addr_type&&e.attributes.StAddr&&e.attributes.City?o.name+=" - "+e.attributes.StAddr+", "+e.attributes.City:e.attributes.Addr_type&&"POI"===e.attributes.Addr_type&&e.attributes.City&&(o.name+=" - "+e.attributes.City)):e.hasOwnProperty("address")&&"string"==typeof e.address?o.name=e.address:e.hasOwnProperty("address")&&"object"==typeof e.address&&e.address.hasOwnProperty("Address")?e.address.hasOwnProperty("Match_addr")?o.name=e.address.Match_addr:e.address.hasOwnProperty("Address")&&(o.name=e.address.Address):o.feature&&o.feature.geometry&&(o.name=o.feature.geometry.x+","+o.feature.geometry.y);return u.featureLayer&&o.feature&&V(o.feature,u.featureLayer),o}},_getScale:function(){var e;return this.map&&"function"==typeof this.map.getScale&&(e=this.map.getScale()),e},_hydrateResults:function(e,t,s,i){var r=[],a=0;if(e&&e.length)for(a;a<e.length;a++){var o=this._hydrateResult(e[a],t,s);o&&r.push(o)}return r},_containsNonLatinCharacter:function(e){for(var t=0;t<e.length;t++)if(e.charCodeAt(t)>255)return!0;return!1},_setPlaceholder:function(e){var t="",s=this.sources,i=s[e];e===this._allIndex?t=this.allPlaceholder||y.widgets.Search.main.allPlaceholder:i&&i.placeholder&&(t=i.placeholder);var r=y.widgets.Search.main.all;i&&(r=this._getSourceName(e)),d.set(this.sourceNameNode,"textContent",r),d.set(this.inputNode,"placeholder",t),d.set(this.inputNode,"title",t)},_updateActiveSource:function(){var e,t=this.sources,s=this.activeSourceIndex;t&&t[s]&&(e=t[s]),e?this.set("activeSource",e):this.set("activeSource",null)},_updateVisible:function(){this.visible?this.show():this.hide()},_updateButtonMode:function(e){e?(f.toggle(this.containerNode,this.css.searchExpanded,this.expanded),f.toggle(this.containerNode,this.css.searchCollapsed,!this.expanded),f.add(this.containerNode,this.css.hasButtonMode)):(f.remove(this.containerNode,this.css.searchExpanded),f.remove(this.containerNode,this.css.searchCollapsed),f.remove(this.containerNode,this.css.hasButtonMode))},_setDefaultActiveSourceIndex:function(e){e&&1===e.length||!this.enableSearchingAll?this.set("activeSourceIndex",0):this.set("activeSourceIndex",this._allIndex)},_setEnableSourcesMenuAttr:function(e){this._set("enableSourcesMenu",e),this._created&&this._insertSources(this.sources)},_setEnableSearchingAllAttr:function(e){this._set("enableSearchingAll",e),this._created&&(this._setDefaultActiveSourceIndex(this.sources),this._hideMenus(),this._insertSources(this.sources))},_setSourcesAttr:function(e){this._createSourceNameMap(e).then(s.hitch(this,function(t){this._sourceNames=t,this._created&&(this._setDefaultActiveSourceIndex(e),this._hideMenus(),this._insertSources(e))})),this._set("sources",e)},_setAllPlaceholderAttr:function(e){this._set("allPlaceholder",e),this._created&&this._setPlaceholder(this.activeSourceIndex)},_setActiveSourceIndexAttr:function(e){this._set("activeSourceIndex",e),this._updateActiveSource(),this._created&&(this._setPlaceholder(e),this._hideMenus(),this._insertSources(this.sources))},_setMaxLengthAttr:function(e){this._set("maxLength",e),this._created&&d.set(this.inputNode,"maxLength",e)},_setValueAttr:function(e){this.set("magicKey",null),this.set("selectedFeatureId",null),this._set("value",e),this._created&&(d.set(this.inputNode,"value",e),this._checkStatus())},_setVisibleAttr:function(e){this._set("visible",e),this._created&&this._updateVisible()},_setEnableButtonModeAttr:function(e){this._set("enableButtonMode",e),this._created&&this._updateButtonMode(e)},_setThemeAttr:function(e){this._created&&(f.remove(this.domNode,this.theme),f.add(this.domNode,e)),this._set("theme",e)}});return u("extend-esri")&&s.setObject("dijit.Search",q,L),q});