// 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/aspect dojo/Deferred dojo/_base/lang dojo/_base/html dojo/_base/array dojo/on dojo/_base/declare ./ValueProvider dojo/store/Memory jimu/utils dijit/form/FilteringSelect".split(" "),function(n,m,e,g,l,p,q,r,t,k,u){return q([r],{templateString:"\x3cdiv\x3e\x3c/div\x3e",codedValues:null,staticValues:null,showNullValues:!1,layerDataChanged:!1,ifDropDown:!1,customId:null,postCreate:function(){this.inherited(arguments);g.addClass(this.domNode,"jimu-filter-list-value-provider");this.customId=
this.partObj.vpId;this._initValueSelect();this._uniqueValueCache={};this.noDataTips='\x3cdiv class\x3d"error-tip-section" style\x3d"display: block;"\x3e\x3cspan class\x3d"jimu-icon jimu-icon-error"\x3e\x3c/span\x3e\x3cspan class\x3d"jimu-state-error-text"\x3e'+this.nls.noFilterValueTip+"\x3c/span\x3e\x3c/div\x3e";var a=new t({idProperty:"id",data:[]});this.valuesSelect.set("store",a);this.isNumberField=k.isNumberField(this.fieldInfo.type);!this.staticValues&&"function"===typeof this.valuesSelect._onDropDownMouseDown&&
(!this.codedValues||this.codedValues&&this.filterCodedValue)&&(this.own(n.before(this.valuesSelect,"_onDropDownMouseDown",e.hitch(this,this._onBeforeDropDownMouseDown))),this.own(p(document.body,"click",e.hitch(this,this._onBodyClick))),this.layerInfo&&this.layerInfo.getLayerObject().then(e.hitch(this,function(c){c.on("edits-complete",e.hitch(this,function(){this.layerDataChanged=!0}))})))},_initValueSelect:function(){var a={searchAttr:"label",required:!1,intermediateChanges:!0};this.customId&&(a["aria-label"]=
this.partObj.interactiveObj.prompt+" "+this.partObj.interactiveObj.hint);this.valuesSelect=new u(a);this.valuesSelect.startup();this.valuesSelect.on("input",e.hitch(this,this._onFilteringSelectInput));g.setStyle(this.valuesSelect.domNode,"width","100%");this.valuesSelect.placeAt(this.domNode)},_onFilteringSelectInput:function(){this.emit("change")},_getCodedValueLabelsBySubTypeId:function(){var a=this.getDropdownFilterPartsObj();return this.getCodedValueListByPartsObj(this.layerDefinition,this.fieldName,
a,this.codedValues)},_onBeforeDropDownMouseDown:function(){this.ifDropDown=!0;this._tryUpdatingUniqueValues(void 0,!0);return arguments},_onBodyClick:function(a){a=a.target||a.srcElement;a===this.domNode||g.isDescendant(a,this.domNode)||this.msgDiv&&g.setStyle(this.msgDiv,"display","none")},getDijits:function(){return[this.valuesSelect]},isValidValue:function(){return 0<this.getStatus()},getStatus:function(){var a=this.valuesSelect.get("item");if(a&&void 0!==a.value){if(this.isNumberField&&!k.isValidNumber(a.value)&&
"value"===this.partObj.valueObj.type){var c=parseFloat(a.value);return k.isValidNumber(c)?(a.value=c,this._getStatusForDijit(this.valuesSelect)):-1}return this._getStatusForDijit(this.valuesSelect)}return 0},_getStatusForDijit:function(a){return a.validate()?a.get("DisplayedValue")?1:0:-1},setValueObject:function(a){return this.staticValues?this._setValueForStaticValues(a.value,this.staticValues):this.codedValues?this.filterCodedValue?this._tryUpdatingUniqueValues(a.value,!1):this._setValueForStaticValues(a.value,
this.codedValues):this._tryUpdatingUniqueValues(a.value,!1)},getValueObject:function(){if(this.isValidValue()){var a=this.valuesSelect.get("item").value;return{isValid:!0,type:this.partObj.valueObj.type,value:a}}return null},tryGetValueObject:function(){return this.isValidValue()?this.getValueObject():this.isEmptyValue()?{isValid:!0,type:this.partObj.valueObj.type,value:"string"===this.shortType?"":null}:null},setRequired:function(a){this.valuesSelect.set("required",a)},_setValueForStaticValues:function(a,
c){var b=null,f=-1;b=null;c&&(b=l.map(c,e.hitch(this,function(d,h){d={id:h,value:d.value,label:d.label};d.value+""===a+""&&(f=h);return d})),this.valuesSelect.store.setData(b),0<=f&&(b=this.valuesSelect.store.get(f))&&this.valuesSelect.set("item",b),this._checkIfNoData())},_uniqueValueLoadingDef:null,_uniqueValueLoadingExpr:"",_uniqueValueCache:null,_tryUpdatingUniqueValues:function(a,c){var b=new m;if(this.valuesSelect._opened)this._checkIfNoData(),b.resolve();else{var f=this.getDropdownFilterExpr();
f!==this._uniqueValueLoadingExpr||this.layerDataChanged?(this.valuesSelect.readOnly=!0,this._uniqueValueLoadingDef&&(this._uniqueValueLoadingDef.reject(),this._uniqueValueLoadingDef=null),this._uniqueValueLoadingExpr=f,this._uniqueValueLoadingDef=this._getUniqueValues(f),this._uniqueValueLoadingDef.then(e.hitch(this,function(d){this.domNode&&(this._uniqueValueLoadingDef=null,this.valuesSelect.readOnly=!1,this._setValueForUniqueValues(a,d),this._hideLoadingIcon(),c&&this.valuesSelect.toggleDropDown(),
this._checkIfNoData(),b.resolve())}),e.hitch(this,function(d){console.error(d);this.domNode&&(this._uniqueValueLoadingDef=null,this.valuesSelect.readOnly=!1,this._hideLoadingIcon(),this._checkIfNoData(),b.reject(d))}))):(this._checkIfNoData(),b.resolve())}return b},_setValueForUniqueValues:function(a,c){c.sort(function(d,h){return d.value<h.value?-1:d.value===h.value?0:1});this.showNullValues||(c=l.filter(c,e.hitch(this,function(d){return"\x3cNull\x3e"!==d.value&&null!==d.value})));if(void 0===a){var b=
this.getValueObject();b&&(a=b.value)}var f=-1;b=null;c=l.map(c,e.hitch(this,function(d,h){var v={id:h,value:d.value,label:d.label};d.value+""===a+""&&(f=h);return v}));this.valuesSelect.store.setData(c);0<=f&&(b=this.valuesSelect.store.get(f));this.valuesSelect.set("item",b)},_checkIfNoData:function(){this.runtime&&this.ifDropDown&&(this.ifDropDown=!1,0===this.valuesSelect.store.data.length&&(this.msgDiv?g.setStyle(this.msgDiv,"display","block"):(this.msgDiv=document.createElement("div"),g.addClass(this.msgDiv,
"jimu-filter-list-value-provider-tip-container"),this.msgDiv.innerHTML=this.noDataTips,this.valuesSelect.domNode.parentNode.appendChild(this.msgDiv))))},_showLoadingIcon:function(){g.addClass(this.valuesSelect.domNode,"loading")},_hideLoadingIcon:function(){g.removeClass(this.valuesSelect.domNode,"loading")},_getUniqueValues:function(a){var c=new m;this._uniqueValueCache[a]&&!this.layerDataChanged?c.resolve(this._uniqueValueCache[a]):(this._showLoadingIcon(),k.getUniqueValues(this.url,this.fieldName,
a,this.layerDefinition,this.fieldPopupInfo).then(e.hitch(this,function(b){this.domNode&&(this._uniqueValueCache[a]=b,c.resolve(b),this._hideLoadingIcon())}),e.hitch(this,function(b){this.domNode&&(c.reject(b),this._hideLoadingIcon())})));this.layerDataChanged=!1;return c}})});