/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["../../chunks/_rollupPluginBabelHelpers","../../chunks/tslib.es6","../../core/Accessor","../../core/arrayUtils","../../core/Collection","../../core/collectionUtils","../../core/Handles","../../core/maybe","../../core/promiseUtils","../../core/accessorSupport/decorators/property","../../core/has","../../core/accessorSupport/ensureType","../../core/accessorSupport/decorators/subclass","./support/layerUtils","./support/validation"],(function(e,t,r,a,l,o,n,s,i,u,d,h,c,y,p){"use strict";let _=function(t){function r(e){var r;return(r=t.call(this,e)||this).state="disabled",r._handles=new n,r._valueBeforeReady=null,r._domainInfo=p.getDomainInfo([]),r._loadLayers=y.createLoadLayersFunction(),r.layers=new l,r}e._inheritsLoose(r,t);var u=r.prototype;return u.initialize=function(){this._handles.add(this.layers.on("change",(()=>this._onLayersChange()))),this._onLayersChange()},u.destroy=function(){this._set("state","disabled"),this._handles.destroy()},u.select=function(e){if("ready"!==this.state)return void(this._valueBeforeReady=e);const t=p.getValidNumber(e,this);s.isSome(t)&&(this.enabled=!0,this.value=e)},u.clear=function(){"ready"===this.state?this.enabled=!1:this._valueBeforeReady=null},u.next=function(){const{state:e,allowedValues:t,enabled:r,hasNext:a,_valueIndex:l}=this;if("ready"!==e&&s.isSome(this._valueBeforeReady))this._valueBeforeReady++;else if(0!==t.length)return r?void(a&&(this.value=t[l+1])):(this.enabled=!0,void(this.value=t[0]))},u.previous=function(){const{state:e,allowedValues:t,enabled:r,hasPrevious:a,_valueIndex:l}=this;if("ready"!==e&&s.isSome(this._valueBeforeReady))this._valueBeforeReady++;else if(0!==t.length)return r?void(a&&(this.value=t[l-1])):(this.enabled=!0,void(this.value=t[t.length-1]))},u.getValueLabel=function(e){var t;return 0===this.layers.length?null:null!=(t=this._domainInfo.fieldValueMap.get(e))?t:null},u._onLayersChange=function(){var t=e._asyncToGenerator((function*(){if(this._set("state","loading"),this._domainInfo=p.getDomainInfo([]),0!==this.layers.length)try{yield this._loadLayers(this.layers),this._setup()}catch(e){i.isAbortError(e)||this._set("state","failed")}}));function r(){return t.apply(this,arguments)}return r}(),e._createClass(r,[{key:"enabled",get:function(){return this.allowedValues.length>0&&this._get("enabled")},set:function(e){e!==this.enabled&&this.allowedValues.length>0&&this._set("enabled",e)}},{key:"value",get:function(){const e="ready"===this.state?this._get("value"):this._valueBeforeReady;return s.unwrapOr(e,0)},set:function(e){if("ready"!==this.state)return void(this._valueBeforeReady=e);if(e===this.value)return;const t=p.getValidNumber(e,this);s.isNone(t)||this._set("value",t)}},{key:"min",get:function(){return p.getMin(this.allowedValues)}},{key:"max",get:function(){return p.getMax(this.allowedValues)}},{key:"allowedValues",get:function(){return this._domainInfo.allowedValues}},{key:"hasNext",get:function(){if(!this.enabled)return!0;const e=this._valueIndex;return e>=0&&e<this.allowedValues.length-1}},{key:"hasPrevious",get:function(){return!this.enabled||this._valueIndex>0}},{key:"layers",set:function(e){const t=this._get("layers");this._set("layers",o.referenceSetter(e,t))}},{key:"filterExpressions",get:function(){return{solid:null,xRay:null}}},{key:"_valueIndex",get:function(){return a.binaryIndexOf(this.allowedValues,this.value)}}]),r}(r);t.__decorate([u.property({value:!1,nonNullable:!0})],_.prototype,"enabled",null),t.__decorate([u.property({nonNullable:!0})],_.prototype,"value",null),t.__decorate([u.property({readOnly:!0})],_.prototype,"min",null),t.__decorate([u.property({readOnly:!0})],_.prototype,"max",null),t.__decorate([u.property({readOnly:!0})],_.prototype,"allowedValues",null),t.__decorate([u.property({readOnly:!0})],_.prototype,"hasNext",null),t.__decorate([u.property({readOnly:!0})],_.prototype,"hasPrevious",null),t.__decorate([u.property({type:l,nonNullable:!0})],_.prototype,"layers",null),t.__decorate([u.property({nonNullable:!0})],_.prototype,"state",void 0),t.__decorate([u.property()],_.prototype,"_valueBeforeReady",void 0),t.__decorate([u.property({readOnly:!0})],_.prototype,"_valueIndex",null),t.__decorate([u.property()],_.prototype,"_domainInfo",void 0),_=t.__decorate([c.subclass("esri.widgets.BuildingExplorer.BuildingNumericFilterViewModel")],_);return _}));
