// 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/Evented dojo/_base/lang dojo/_base/html dojo/_base/array dojo/_base/declare dijit/_WidgetBase dijit/_TemplatedMixin dijit/_WidgetsInTemplateMixin dojo/store/Memory dojo/store/Observable dijit/tree/ObjectStoreModel jimu/dijit/_Tree jimu/DataSourceManager".split(" "),function(p,f,m,l,q,r,t,u,v,w,x,y,z){return q([r,t,u,p],{baseClass:"jimu-dijit-framework-datasource-chooser",templateString:'\x3cdiv\x3e\x3cdiv class\x3d"no-data-section"\x3e\x3cdiv class\x3d"jimu-widget-note tip1"\x3e${nls.noExtraDsAvailable}\x3c/div\x3e\x3cdiv class\x3d"jimu-widget-note tip2"\x3e${nls.addExtraDsTip}\x3c/div\x3e\x3c/div\x3e\x3c/div\x3e',
dataSourceManager:null,_store:null,_id:0,tree:null,appConfig:null,postMixInProperties:function(){this.nls=window.jimuNls.frameworkDatasource;this.dataSourceManager=z.getInstance()},postCreate:function(){this.inherited(arguments);m.addClass(this.domNode,"no-data");this._createTree();var a=this.appConfig.dataSource&&this.appConfig.dataSource.dataSources;if(a){var b=Object.keys(a),d={},g=[],h=[];l.forEach(b,f.hitch(this,f.hitch(this,function(c){var e=this.dataSourceManager.parseDataSourceId(c),k=a[c];
if(e)if(c={dsId:c,dsTypeInfo:e,ds:k},"widget"===e.from){if(e=e.widgetId)d[e]||(d[e]={widgetInfo:this.appConfig.getConfigElementById(e),arr:[]}),d[e].arr.push(c)}else"Features"===k.type?g.push(c):"FeatureStatistics"===k.type&&h.push(c)})));b=Object.keys(d);0<b.length&&(this._addWidgetsOutpusItem(),l.forEach(b,f.hitch(this,function(c){var e=d[c],k=e.widgetInfo&&e.widgetInfo.label;k||(k=c);var A=this._addWidgetLabelItem(k);e.arr&&0<e.arr.length&&l.forEach(e.arr,f.hitch(this,function(n){this._addWidgetDataSourceItem(A.id,
n.ds.label,n.ds.id)}))})));0<g.length&&l.forEach(g,f.hitch(this,function(c){this._addLayerDataSource(c.ds.label,c.ds.id)}));0<h.length&&l.forEach(h,f.hitch(this,function(c){this._addStatisticsDataSource(c.ds.label,c.ds.id)}));(0<b.length||0<g.length||0<h.length)&&m.removeClass(this.domNode,"no-data")}},getSelectedItems:function(){var a=this.tree.getSelectedItems();return a=l.map(a,f.hitch(this,function(b){return{dsId:b.dsId,name:b.name}}))},_createTree:function(){var a=this._getRootItem();a=new v({data:[a],
getChildren:function(b){return this.query({parent:b.id})}});this._store=new w(a);a=new x({store:this._store,query:{id:"root"},mayHaveChildren:f.hitch(this,this._mayHaveChildren)});this.tree=new y({multiple:!1,model:a,showRoot:!1,isLeafItem:f.hitch(this,this._isLeafItem),style:{width:"100%"},onOpen:f.hitch(this,function(b,d){"root"!==b.id&&this._onTreeOpen(b,d)}),onClick:f.hitch(this,function(b,d,g){this._onTreeClick(b,d,g);this.emit("tree-click",b,d,g)}),getIconStyle:f.hitch(this,function(b,d){var g=
null;if(!b||"root"===b.id)return null;var h={width:"20px",height:"20px",backgroundRepeat:"no-repeat",backgroundPosition:"center center",backgroundImage:""},c="//"+window.location.host+require.toUrl("jimu");if(b=this._getIconImageName(b,d))h.backgroundImage="url("+c+"/css/images/"+b+")",g=h;return g})});this.tree.placeAt(this.domNode)},_addItem:function(a,b,d,g,h,c){this._id++;a={id:this._id.toString(),type:a,parent:b,name:d||"",isLeaf:g,hasChildren:h,dsId:c||""};this._store.add(a);return a},_getRootItem:function(){return{id:"root",
type:"root",name:"DataSource Root",isLeaf:!1,hasChildren:!0}},_addWidgetsOutpusItem:function(){var a={id:"widgetsOutput",type:"widgetsOutput",parent:"root",name:"Widgets output",isLeaf:!1,hasChildren:!0};this._store.add(a);return a},_addWidgetLabelItem:function(a){return this._addItem("widgetLabel","widgetsOutput",a,!1,!0)},_addWidgetDataSourceItem:function(a,b,d){return this._addItem("widgetDataSource",a,b,!0,!1,d)},_addLayerDataSource:function(a,b){return this._addItem("layerDataSource","root",
a,!0,!1,b)},_addStatisticsDataSource:function(a,b){return this._addItem("statisticsDataSource","root",a,!0,!1,b)},_getIconImageName:function(){return""},_mayHaveChildren:function(a){return a.hasChildren},_isLeafItem:function(a){return a.isLeaf},_onTreeOpen:function(){},_onTreeClick:function(){}})});