/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
import{__decorate as e}from"tslib";import t from"../../core/Accessor.js";import{binaryIndexOf as l}from"../../core/arrayUtils.js";import s from"../../core/Collection.js";import{referenceSetter as a}from"../../core/collectionUtils.js";import{deprecateUnnecessaryViewModel as r}from"../../core/deprecate.js";import i from"../../core/Logger.js";import{isAbortError as o}from"../../core/promiseUtils.js";import{property as n,subclass as u}from"../../core/accessorSupport/decorators.js";import{createLoadLayersFunction as d}from"./support/layerUtils.js";import{getDomainInfo as h,getValidNumber as p,getMin as y,getMax as v}from"./support/validation.js";let g=class extends t{constructor(e){super(e),this.state="disabled",this._valueBeforeReady=null,this._domainInfo=h([]),this._loadLayers=d(),e?.suppressDeprecationWarning||r(i.getLogger(this),"Building Explorer","arcgis-building-explorer",{version:"5.0"}),this.layers=new s}normalizeCtorArgs(e){const{suppressDeprecationWarning:t,...l}=e??{};return l}initialize(){this.addHandles(this.layers.on("change",()=>this._onLayersChange())),this._onLayersChange()}destroy(){this._set("state","disabled")}get enabled(){return this.allowedValues.length>0&&this._get("enabled")}set enabled(e){e!==this.enabled&&this.allowedValues.length>0&&this._set("enabled",e)}get value(){return("ready"===this.state?this._get("value"):this._valueBeforeReady)??0}set value(e){if("ready"!==this.state)return void(this._valueBeforeReady=e);if(e===this.value)return;const t=p(e,this);null!=t&&this._set("value",t)}get min(){return y(this.allowedValues)}get max(){return v(this.allowedValues)}get allowedValues(){return this._domainInfo.allowedValues}set allowedValues(e){null==e?this._clearOverride("allowedValues"):this._override("allowedValues",e);const t=p(this.value,this);null!=t&&(this.value=t)}get hasNext(){if(!this.enabled)return!0;const e=this._valueIndex;return e>=0&&e<this.allowedValues.length-1}get hasPrevious(){return!this.enabled||this._valueIndex>0}set layers(e){const t=this._get("layers");this._set("layers",a(e,t))}get filterExpressions(){return{solid:null,xRay:null}}get _valueIndex(){return l(this.allowedValues,this.value)}select(e){if("ready"!==this.state)return void(this._valueBeforeReady=e);null!=p(e,this)&&(this.enabled=!0,this.value=e)}clear(){"ready"===this.state?this.enabled=!1:this._valueBeforeReady=null}next(){const{state:e,allowedValues:t,enabled:l,hasNext:s,_valueIndex:a}=this;if("ready"===e||null==this._valueBeforeReady){if(0!==t.length)return l?void(s&&(this.value=t[a+1])):(this.enabled=!0,void(this.value=t[0]))}else this._valueBeforeReady++}previous(){const{state:e,allowedValues:t,enabled:l,hasPrevious:s,_valueIndex:a}=this;if("ready"===e||null==this._valueBeforeReady){if(0!==t.length)return l?void(s&&(this.value=t[a-1])):(this.enabled=!0,void(this.value=t[t.length-1]))}else this._valueBeforeReady++}getValueLabel(e){return 0===this.layers.length?null:this._domainInfo.fieldValueMap.get(e)??null}async _onLayersChange(){if(this._set("state","loading"),this._domainInfo=h([]),0!==this.layers.length)try{await this._loadLayers(this.layers),this._setup()}catch(e){o(e)||this._set("state","failed")}}};e([n({value:!1,nonNullable:!0})],g.prototype,"enabled",null),e([n({nonNullable:!0})],g.prototype,"value",null),e([n({readOnly:!0})],g.prototype,"min",null),e([n({readOnly:!0})],g.prototype,"max",null),e([n()],g.prototype,"allowedValues",null),e([n({readOnly:!0})],g.prototype,"hasNext",null),e([n({readOnly:!0})],g.prototype,"hasPrevious",null),e([n({type:s,nonNullable:!0})],g.prototype,"layers",null),e([n({nonNullable:!0})],g.prototype,"state",void 0),e([n()],g.prototype,"_valueBeforeReady",void 0),e([n({readOnly:!0})],g.prototype,"_valueIndex",null),e([n()],g.prototype,"_domainInfo",void 0),g=e([u("esri.widgets.BuildingExplorer.BuildingNumericFilterViewModel")],g);const c=g;export{c as default};
