// All material copyright ESRI, All Rights Reserved, unless otherwise specified.
// See http://js.arcgis.com/3.23/esri/copyright.txt for details.
//>>built
define("esri/dijit/RasterFunctionEditor/RFxWeightedSumTableEditor","dojo/_base/declare dojo/has ../../kernel dojo/i18n!../../nls/jsapi dgrid/OnDemandGrid dgrid/Keyboard dgrid/editor dojo/store/Memory dojo/store/Observable dojo/data/ObjectStore dojo/on dojo/_base/lang dojo/Evented dojo/_base/array dijit/_WidgetBase dijit/_TemplatedMixin dijit/_WidgetsInTemplateMixin dijit/form/NumberTextBox dijit/form/Select ./EditableGridMixin ./utils".split(" "),function(g,p,q,r,t,u,v,h,w,k,F,e,x,l,y,z,A,B,m,C,n){var D=
g([t,u]),E=["esriFieldTypeSmallInteger","esriFieldTypeInteger","esriFieldTypeSingle","esriFieldTypeDouble"];g=g([y,z,A,x,C],{templateString:"\x3cdiv\x3e\x3cdiv data-dojo-attach-point\x3d'gridNode'\x3e\x3c/div\x3e\x3c/div\x3e",baseClass:"esriRFxWeightedSumTableEditor",postCreate:function(){this.inherited(arguments);this._i18n=r.widgets.rasterFunctionEditor.rfxWeightedSumTableEditor;this._initStore();this._initGrid();this.attachGridEvents();this.own(this.on("change",e.hitch(this,this._updateArgValues)))},
_updateArgValues:function(){var a=this.inputArgs,c=this._store.data;if(a){var d=a.Rasters,b=a.Weights,f=a.Fields;d&&(d.value=[]);b&&(b.value=[]);f&&(f.value=[]);l.forEach(c,function(a){if("*"!==a.idNum&&"blank_item"!==a.layerSelect.value){var c=a.layerSelect.store.get(a.layerSelect.value);d&&d.value&&d.value.push(n.getRasterJsonFromLayer(c));b&&b.value&&b.value.push(a.weight);f&&f.value&&f.value.push(a.fieldSelect.value)}})}},_readArgValues:function(){if(this.inputArgs){var a,c=0,d=[],b=this.inputArgs,
f=b.Rasters,e=b.Weights,b=b.Fields;if(f&&e&&b&&(a=Math.min(f.value&&f.value.length,e.value&&e.value.length,b.value&&b.value.length),isNaN(a)))return d;for(;c<a;)d.push({layer:n.getLayerIdfromRasterValue(f.value[c],this.inputLayers),idNum:c+1,id:c+1,field:b.value[c],weight:e.value[c]}),c+=1;return d}},_onFieldChange:function(a){a&&a.fieldSelect&&("*"===a.idNum&&this._addBlankObject(),a.weight=1,a.field=a.fieldSelect.value,this._onDataChange())},_onLayerChange:function(a){if(a&&a.fieldSelect&&a.layerSelect){var c=
a.layerSelect,d=a.fieldSelect,b=c.value,c=c.store.get(b);a.layer=b;c.getRasterAttributeTable({renderingRule:c.renderingRule}).then(e.hitch(this,function(b){b&&b.fields?(a.fieldStore=this._getFieldStore(b.fields),d.set("store",a.fieldStore)):d.set("store",this._getFieldStore())}),e.hitch(this,function(a){d.set("store",this._getFieldStore())}));a.weight=1;"*"===a.idNum&&this._addBlankObject();this._onDataChange()}},_getLayersOptions:function(){return new k(new h({data:this.inputLayers.concat([{id:"blank_item",
name:this._i18n.selectLayer}]),idProperty:"id"}))},_getFieldStore:function(a){return a&&a.length?(a=l.filter(a,function(a){return-1<l.indexOf(E,a.type)}),new k(new h({data:a,idProperty:"name"}))):new k(new h({data:[{name:"VALUE",alias:this._i18n.value}],idProperty:"name"}))},_initStore:function(){this._store=w(new h({data:this._readArgValues(),idProperty:"id"}))},_initGrid:function(){this._grid=new D({store:this._store,columns:[{field:"idNum",label:this._i18n.id},{field:"layer",label:this._i18n.layer,
renderCell:e.hitch(this,function(a,c,d,b){b=new m({labelAttr:"name",store:this._getLayersOptions(),onChange:e.hitch(this,this._onLayerChange,a),value:"blank_item"});b.getOptions("blank_item").disabled=!0;b.placeAt(d);b.startup();if(""!==c)try{b.attr("value",c,!1)}catch(f){b.attr("value","blank_item")}a.layerSelect=b})},{field:"field",label:this._i18n.field,renderCell:e.hitch(this,function(a,c,d,b){b=new m({labelAttr:"alias",onChange:e.hitch(this,this._onFieldChange,a),store:a.fieldStore||this._getFieldStore()});
try{b.attr("value",c,!1)}catch(f){}b.placeAt(d);b.startup();a.fieldSelect=b})},v({field:"weight",label:this._i18n.weight,editor:B,editorArgs:{required:!0}})]},this.gridNode);this._addBlankObject()}});p("extend-esri")&&e.setObject("dijit.RasterFunctionEditor.RFxWeightedSumTableEditor",g,q);return g});