// 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/declare","./FilteringSelect","esri/dijit/geoenrichment/SelectableTree","../../widgets/SelectableTreeGrid/SelectableTreeGrid","xstyle/css!./css/FilteringSelect.css"],function(g,n,q,l){function r(a,b){var c=[];a.forEach(function(e){e.children.forEach(function(f){var d={};d[b.idProperty]=f[b.idProperty];d[b.labelProperty]=f[b.labelProperty];d.__item=f;c.push(d)})});return c}function t(a,b,c){var e={};b.forEach(function(d){e[d[c.idProperty]]=d});var f=[];a.forEach(function(d){var p=
d.children.filter(function(h){return e[h[c.idProperty]]});if(p.length){var k={};k[c.idProperty]=d[c.idProperty];k[c.labelProperty]=d[c.labelProperty];k.children=p.map(function(h){var m={};m[c.idProperty]=h[c.idProperty];m[c.labelProperty]=h[c.labelProperty];return m});f.push(k)}});return{treeData:f,idsHash:e}}l=g(l,{showRootCheckbox:!1,showCheckboxColumn:!1,enableRowSelection:!0,expandOnNodeClick:!0,baseTree:null,hostWidget:null,defaultExpand:null,_firstTimeExpand:!0,getLabel:function(a,b){return a[this.labelProperty]},
onRowsSelected:function(a,b){a=a&&a[0];b=b&&b[0];a&&!a.children&&(b.setAttribute("item",a[this.idProperty]),this.onChange(b))},createOptions:function(a,b,c){a=t(this.baseTree.data,a,this);this.items=a.idsHash;this.tree.clear();if(this._firstTimeExpand){this._firstTimeExpand=!1;if(this.defaultExpand)var e=Object.assign({},this.defaultExpand);else{e={};var f=this;a.treeData.forEach(function(d){e[d[f.idProperty]]=!0})}this.grid._expanded=e}this.tree.addNodes(a.treeData);this.refresh()},getHighlightedOption:function(){},
highlightFirstOption:function(){},highlightLastOption:function(){},clearResultList:function(){this.tree.clear()},onChange:function(a){}});g=g(n,{dropDownClass:l,tree:null,autoComplete:!1,defaultExpand:null,postCreate:function(){this.inherited(arguments);this.tree&&this.setItems(this._getStoreItemsFromTree())},_setTreeAttr:function(a){this.tree=a;this._isCreated&&this.setItems(this._getStoreItemsFromTree());this.dropDown&&(this.dropDown.baseTree=this.tree)},_getStoreItemsFromTree:function(){return r(this.tree.data,
this)},_startSearch:function(a){if(!this.dropDown){var b=this.id+"_popup";this.dropDown=new this.dropDownClass({gridClass:"esriMapsAnalystXSelectableTreeGrid esriMapsAnalystXFilteringSelect_treeGrid",onChange:function(){return this._selectOption.apply(this,arguments)}.bind(this),id:b,dir:this.dir,textDir:this.textDir,tree:new q([],{idProperty:this.idProperty}),idProperty:this.idProperty,labelProperty:this.labelProperty,baseTree:this.tree,hostWidget:this,defaultExpand:this.defaultExpand})}this.inherited(arguments)},
_openResultList:function(){this.inherited(arguments);this.dropDown&&this.dropDown.refresh()},getSelectedItem:function(){var a=this.inherited(arguments);return a&&a.__item}});g.NONE_ID=n.NONE_ID;return g});