// 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/NearMe/filter-list.html":'\x3cdiv\x3e\r\n  \x3cul class\x3d"filter-list" data-dojo-attach-point\x3d"filterList"\x3e\x3c/ul\x3e\r\n\x3c/div\x3e'}});
define("dojo/_base/declare dojo/text!./filter-list.html dojo/_base/array dojo/_base/html dojo/_base/lang dojo/query dojo/on dojo/dom-attr dojo/keys dijit/_WidgetsInTemplateMixin dojo/dom-class jimu/utils jimu/BaseWidget jimu/filterUtils jimu/dijit/FilterParameters esri/symbols/jsonUtils jimu/symbolUtils jimu/LayerInfos/LayerInfos jimu/FilterManager esri/request dojo/Evented dojo/NodeList dojo/NodeList-dom".split(" "),function(x,y,t,f,h,k,p,l,m,z,q,u,A,B,C,D,v,E,F,G,H){return x([A,z,H],{name:"NearMeFilter",
templateString:y,lastFocusNode:null,baseClass:"jimu-widget-nearme-filter",_itemTemplate:'\x3cli aria-label\x3d"${layerTitle} ${filterNotAppliedLabel}" role\x3d"listitem" tabindex\x3d"0" class\x3d"filter-item" data-index\x3d"${index}"\x3e\x3cdiv class\x3d"header" \x3e\x3cspan role\x3d"button" aria-label\x3d"${toggleTip}" class\x3d"arrow jimu-float-leading jimu-trailing-margin05" title\x3d"${toggleTip}" \x3e\x3c/span\x3e\x3cspan class\x3d"icon"\x3e\x3cimg src\x3d"${icon}" /\x3e\x3c/span\x3e\x3cspan class\x3d"icon symbolIcon" style\x3d"display:none;"\x3e\x3c/span\x3e\x3cspan class\x3d"item-title"\x3e${title}\x3c/span\x3e\x3cspan class\x3d"cando jimu-float-trailing esriCTFliterListCheckbox"\x3e\x3c/span\x3e\x3cspan class\x3d"doing jimu-float-trailing esriCTFliterListCheckbox"\x3e\x3c/span\x3e\x3cspan class\x3d"done jimu-float-trailing esriCTFliterListCheckbox"\x3e\x3c/span\x3e\x3c/div\x3e\x3cdiv class\x3d"body"\x3e\x3cdiv class\x3d"parameters"\x3e\x3c/div\x3e\x3cdiv tabindex\x3d"0" role\x3d"button" aria-label\x3d"${apply}" class\x3d"jimu-btn apply jimu-float-trailing jimu-trailing-margin25"\x3e${apply}\x3c/div\x3e\x3c/div\x3e\x3c/li\x3e',
_layerTitleTemplate:'\x3cdiv class\x3d"esriCTGroupFilterLayerName"\x3e${layerTitle}\x3c/div\x3e',_store:null,totalAppliedFilters:0,postCreate:function(){this.inherited(arguments);this.totalAppliedFilters=0;this._updateClearAllButtonState();this.own(p(this.clearAllButton,"click",h.hitch(this,this._clearAllFilters)));this.own(p(this.clearAllButton,"keydown",h.hitch(this,function(d){d.keyCode!==m.ENTER&&d.keyCode!==m.SPACE||this._clearAllFilters()})));this._store={};this.layerInfosObj=E.getInstanceSync();
this.filterUtils=new B;this.filterManager=F.getInstance();var a=this.config.filters,b={},e=[];this.config.groupFiltersByLayer?(t.forEach(a,function(d,c){b[d.layerId]||(b[d.layerId]=[],e.push(d.layerId));d.index=c;b[d.layerId].push(d)}),t.forEach(e,h.hitch(this,function(d){var c=this.layerInfosObj.getLayerInfoById(d);c=h.replace(this._layerTitleTemplate,{layerTitle:c.layerObject.name||c.title},/\$\{([^\}]+)\}/ig);c=f.toDom(c);f.place(c,this.filterList);for(c=0;c<b[d].length;c++)this._addFilterInList(b[d][c],
b[d][c].index)}))):t.forEach(a,h.hitch(this,function(d,c){this._addFilterInList(d,c)}))},getLastNode:function(){if(this.lastFocusNode)if(q.contains(this.lastFocusNode,"has-ask-for-value")){var a=u.getFocusNodesInDom(this.lastFocusNode);a=q.contains(this.lastFocusNode,"config-parameters")?a.reverse()[0]:k(".arrow",this.lastFocusNode)[0]}else a=this.lastFocusNode;return a},_addFilterInList:function(a,b){var e=this.filterUtils.isAskForValues(a.filter),d={icon:a.icon?u.processUrlInWidgetConfig(a.icon,
this.folderUrl):this.folderUrl+"/css/images/default_task_icon.png",index:b,title:a.name,layerTitle:a.layerTitle?a.layerTitle:a.name,toggleTip:this.nls.toggleTip,hasValue:e?window.appInfo.isRunInMobile?"block !important":"":"none",isAskForValue:e,apply:h.getObject("jimuNls.common.apply",!1,window)||"Apply",filterNotAppliedLabel:this.nls.filterNotAppliedLabel};this._store[a.layerId]||(this._store[a.layerId]={mapFilterControls:{}});b=h.replace(this._itemTemplate,d,/\$\{([^\}]+)\}/ig);var c=f.toDom(b);
this.lastFocusNode=c;f.place(c,this.filterList);if(a.symbol){b=k(".icon",c);f.setStyle(b[0],"display","none");f.setStyle(b[1],"display","inline-block");var g=D.fromJson(a.symbol),n=a.symbol.url||a.symbol.imageData;n?(g.setWidth(25),g.setHeight(25)):g.setSize(25);g=n?v.createSymbolNode(g):v.createSymbolNode(g,{width:26,height:26});f.place(g,b[1])}this.own(k(".header",c).on("click",h.hitch(this,"enableFilter",c,a,d,!1)));e?(f.addClass(c,"has-ask-for-value"),l.set(c,"tabindex","-1")):(this.own(p(k(".header",
c)[0].parentElement,"keydown",h.hitch(this,"enableFilter",c,a,d,!0))),f.addClass(c,"not-has-ask-for-value"));e=k(".apply",c);b=k(".arrow",c);"none"!==d.hasValue?(l.set(e[0],"type",""),l.set(b[0],"type",""),l.set(b[0],"tabindex","0"),this.own(b.on("click",h.hitch(this,"configFilter",c,a))),this.own(b.on("keydown",h.hitch(this,function(r){if(r.keyCode===m.ENTER||r.keyCode===m.SPACE)this.configFilter(c,a),r.stopPropagation()}))),this.own(e.on("click",h.hitch(this,"applyFilterValues",c,a,!1))),this.own(e.on("keydown",
h.hitch(this,"applyFilterValues",c,a,!0))),f.addClass(c,"requesting"),this.configFilter(c,a,null,h.hitch(this,function(){this.config.collapse&&f.removeClass(c,"config-parameters");a.autoApplyWhenWidgetOpen&&this.enableFilter(c,a,d)}))):(l.set(e[0],"type","hidden"),l.set(b[0],"type","hidden"),a.autoApplyWhenWidgetOpen&&this.enableFilter(c,a,d))},startup:function(){this.inherited(arguments);this.resize()},_getPriorityOfMapFilter:function(a){a=h.getObject(a+".mapFilterControls",!1,this._store);var b=
0,e;for(e in a){var d=a[e];d.priority>b&&(b=d.priority)}return b},_getMapFilterControl:function(a){a=h.getObject(a+".mapFilterControls",!1,this._store);var b=!0,e;for(e in a){var d=a[e];0<d.priority&&(b=!!d.enable)}return b},_setItemFilter:function(a,b,e,d){this._store[a]["filter_item_"+b]=e;e=this._getPriorityOfMapFilter(a);h.setObject(a+".mapFilterControls.filter_item_"+b,{enable:d,priority:e+1},this._store)},_removeItemFilter:function(a,b){delete this._store[a]["filter_item_"+b];delete this._store[a].mapFilterControls["filter_item_"+
b]},_getExpr:function(a){if(!this._store[a])return null;var b=[];a=this._store[a];for(var e in a){var d=a[e];d&&"mapFilterControls"!==e&&b.push("("+d+")")}return b.join(" AND ")},_bindMapUpdateEvents:function(a,b){p.once(this.map,"update-start",h.hitch(this,function(){f.addClass(a,"applying");f.removeClass(a,"applied");l.set(a,"aria-label",a.innerText+this.nls.applyingFilterLabel)}));p.once(this.map,"update-end",h.hitch(this,function(){b?(f.addClass(a,"applied"),l.set(a,"aria-label",a.innerText+this.nls.filterAppliedLabel)):
(f.removeClass(a,"applied"),l.set(a,"aria-label",a.innerText+this.nls.filterNotAppliedLabel));f.removeClass(a,"applying")}))},enableFilter:function(a,b,e,d,c){if(!d||c.keyCode===m.ENTER||c.keyCode===m.SPACE)if(!f.hasClass(a,"config-parameters")||a.filterParams&&a.filterParams.getFilterExpr())if(!e.isAskForValue||a.filterParams&&a.filterParams.getFilterExpr()){e=b.layerId;d=f.getAttr(a,"data-index");c=null;var g=this.layerInfosObj.getLayerInfoById(e);c=f.hasClass(a,"applied");g.isShowInMap()&&g.isInScale()?
this._bindMapUpdateEvents(a,c?!1:!0):c?f.removeClass(a,"applied"):f.addClass(a,"applied");g=null;c?(this._removeItemFilter(e,d),c=this._getExpr(e),g=this._getMapFilterControl(e),this.filterManager.applyWidgetFilter(e,this.id,c,g),this.totalAppliedFilters--):(a=this._getFilterExpr(a,b),this._setItemFilter(e,d,a,b.enableMapFilter),c=this._getExpr(e),g=this._getMapFilterControl(e),this.filterManager.applyWidgetFilter(e,this.id,c,g),this.totalAppliedFilters++);this.filtersUpdated=!0;this._updateClearAllButtonState()}else this.configFilter(a,
b)},configFilter:function(a,b,e,d){a.filterParams?(f.hasClass(a,"config-parameters")?(f.removeClass(a,"config-parameters"),this._changeItemTitleWidth(a,window.appInfo.isRunInMobile?60:45)):(f.addClass(a,"config-parameters"),this._changeItemTitleWidth(a,60)),d&&d(),this.emit("setLastFilterNode",this.getLastNode())):G({url:b.url,content:{f:"json"},handleAs:"json",callbackPrams:"callback"}).then(h.hitch(this,function(c){f.addClass(a,"config-parameters");f.removeClass(a,"requesting");var g=k(".parameters",
a)[0];a.handles=[];a.filterParams=new C;var n=h.clone(b.filter),r=null;b.enableMapFilter&&(r=b.layerId);a.filterParams.build(b.url,c,n,r,this.id);this.own(p(a.filterParams,"change",h.hitch(this,function(w){w?(k(".apply",a).removeClass("disable-apply"),a.expr=w):(delete a.expr,k(".apply",a).addClass("disable-apply"))})));a.expr=a.filterParams.getFilterExpr();a.expr?k(".apply",a).removeClass("disable-apply"):(delete a.expr,k(".apply",a).addClass("disable-apply"));a.filterParams.placeAt(g);this._changeItemTitleWidth(a,
60);d&&d()}));e&&e.target&&e.stopPropagation()},applyFilterValues:function(a,b,e,d){if(!e||d.keyCode===m.ENTER||d.keyCode===m.SPACE){var c=a.filterParams&&(a.expr||this._getFilterExpr(a,b)),g=!0;e=!1;q.contains(a,"applied")?(e=!0,this._getExpr(b.layerId)==="("+c+")"&&(g=!1)):g=!0;if(c&&g){a.expr=c;c=b.layerId;g=f.getAttr(a,"data-index");var n=this.layerInfosObj.getLayerInfoById(c);n.isShowInMap()&&n.isInScale()?this._bindMapUpdateEvents(a,!0):f.addClass(a,"applied");this._setItemFilter(c,g,a.expr,
b.enableMapFilter);a=this._getExpr(c);b=this._getMapFilterControl(c);this.filterManager.applyWidgetFilter(c,this.id,a,b);this.filtersUpdated=!0;e||this.totalAppliedFilters++;this._updateClearAllButtonState()}d.stopPropagation()}},_getFilterExpr:function(a,b){return a.filterParams?a.filterParams.getFilterExpr():this.filterUtils.hasVirtualDate(b.filter)?(this.filterUtils.isHosted=u.isHostedService(b.url),this.filterUtils.getExprByFilterObj(b.filter)):b.filter.expr},resize:function(){this.inherited(arguments);
this._changeItemTitleWidth(this.domNode,window.appInfo.isRunInMobile?60:45)},_changeItemTitleWidth:function(a,b){var e=k(".header",a)[0];e&&(b=f.getContentBox(e).w-b,0<b&&k(".header .item-title",a).style({maxWidth:b+"px"}))},destroy:function(){k(".filter-item",this.filterList).forEach(function(b){delete b.filterParams;delete b.expr});if(this._store)for(var a in this._store)a&&this.filterManager.applyWidgetFilter(a,this.id,"",null);this.inherited(arguments)},filterListShown:function(){this.filtersUpdated=
!1},_updateClearAllButtonState:function(){0<this.totalAppliedFilters?(q.add(this.clearAllButton,"esriCTClearAllFilterActive"),l.set(this.clearAllButton,"aria-disabled","false")):(q.remove(this.clearAllButton,"esriCTClearAllFilterActive"),l.set(this.clearAllButton,"aria-disabled","true"))},_clearAllFilters:function(){if(q.contains(this.clearAllButton,"esriCTClearAllFilterActive")&&this.filterList){var a=k(".applied",this.filterList);t.forEach(a,function(b){(b=k(".header",b))&&0<b.length&&b[0].click()});
this._updateClearAllButtonState();this.emit("clearAllFilters")}}})});