/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
import{__decorate as e}from"tslib";import{property as s,subclass as t}from"../../core/accessorSupport/decorators.js";import l from"./BuildingNumericFilterViewModel.js";import{findFieldInfoByModelName as i}from"./support/buildingLayerUtils.js";import{getValueFromFilters as r}from"./support/filterUtils.js";import{getDomainInfo as o}from"./support/validation.js";const a="demolishedphase",d="createdphase";let n=class extends l{constructor(e){super(e),this._createdPhaseFieldName=null,this._demolishedPhaseFieldName=null,this._parseValueFromFilter=e=>{const s=this._createdPhaseFieldName,t=new RegExp(`${s}\\s*<=\\s*(\\d+)\\s*OR\\s*${s}\\s*IS\\s*NULL`,"gi"),l=this._demolishedPhaseFieldName,i=new RegExp(`${l}\\s*>\\s*(\\d+)\\s*OR\\s*${l}\\s*IS\\s*NULL`,"gi");for(const{filterExpression:r}of e.filterBlocks?.items??[]){const e=r?t.exec(r)??i.exec(r):null;if(e)return parseInt(e[1],10)}return null}}get filterExpressions(){if(!this.enabled)return{solid:null,xRay:null};const e=[],s=this._createdPhaseFieldName;s&&e.push(`(${s} <= ${this.value} OR ${s} IS NULL)`);const t=this._demolishedPhaseFieldName;t&&e.push(`(${t} > ${this.value} OR ${t} IS NULL)`);const l=e.join(" AND ");return{solid:l,xRay:l}}get _lastValue(){const e=this.allowedValues;return e.length>0?e[e.length-1]:0}_setup(){const e=[];this.layers.forEach(s=>{const t=i(s,d);null!=t&&(this._createdPhaseFieldName=t.fieldName,e.push(t));const l=i(s,a);null!=l&&(this._demolishedPhaseFieldName=l.fieldName,e.push(l))}),this._domainInfo=o(e);const s=this._valueBeforeReady;if(this._set("state","ready"),this._valueBeforeReady=null,this.allowedValues.length>0){const e=s??r(this.layers,this._parseValueFromFilter);this.select(e??this._lastValue)}else this.clear()}};e([s({readOnly:!0})],n.prototype,"filterExpressions",null),e([s()],n.prototype,"_createdPhaseFieldName",void 0),e([s()],n.prototype,"_demolishedPhaseFieldName",void 0),e([s({readOnly:!0})],n.prototype,"_lastValue",null),n=e([t("esri.widgets.BuildingExplorer.BuildingPhase")],n);const h=n;export{h as default};
