/*
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/maybe","../../core/accessorSupport/decorators/property","../../core/arrayUtils","../../core/has","../../core/accessorSupport/ensureType","../../core/accessorSupport/decorators/subclass","./BuildingNumericFilterViewModel","./support/buildingLayerUtils","./support/filterUtils","./support/validation"],(function(e,s,t,r,l,i,o,a,n,d,u,c){"use strict";const p="demolishedphase",h="createdphase";let _=function(s){function r(){var e;return(e=s.apply(this,arguments)||this)._createdPhaseFieldName=null,e._demolishedPhaseFieldName=null,e._parseValueFromFilter=s=>{const t=e._createdPhaseFieldName,r=new RegExp(`${t}\\s*<=\\s*(\\d+)\\s*OR\\s*${t}\\s*IS\\s*NULL`,"gi"),l=e._demolishedPhaseFieldName,i=new RegExp(`${l}\\s*>\\s*(\\d+)\\s*OR\\s*${l}\\s*IS\\s*NULL`,"gi");for(const{filterExpression:e}of s.filterBlocks.items){var o;const s=null!=(o=r.exec(e))?o:i.exec(e);if(s)return parseInt(s[1],10)}return null},e}return e._inheritsLoose(r,s),r.prototype._setup=function(){const e=[];this.layers.forEach((s=>{const r=d.findFieldInfoByModelName(s,h);t.isSome(r)&&(this._createdPhaseFieldName=r.fieldName,e.push(r));const l=d.findFieldInfoByModelName(s,p);t.isSome(l)&&(this._demolishedPhaseFieldName=l.fieldName,e.push(l))})),this._domainInfo=c.getDomainInfo(e);const s=this._valueBeforeReady;if(this._set("state","ready"),this._valueBeforeReady=null,this.allowedValues.length>0){const e=null!=s?s:u.getValueFromFilters(this.layers,this._parseValueFromFilter);this.select(t.unwrapOr(e,this._lastValue))}else this.clear()},e._createClass(r,[{key:"filterExpressions",get:function(){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 r=e.join(" AND ");return{solid:r,xRay:r}}},{key:"_lastValue",get:function(){const e=this.allowedValues;return e.length>0?e[e.length-1]:0}}]),r}(n);s.__decorate([r.property({readOnly:!0})],_.prototype,"filterExpressions",null),s.__decorate([r.property()],_.prototype,"_createdPhaseFieldName",void 0),s.__decorate([r.property()],_.prototype,"_demolishedPhaseFieldName",void 0),s.__decorate([r.property({readOnly:!0})],_.prototype,"_lastValue",null),_=s.__decorate([a.subclass("esri.widgets.BuildingExplorer.BuildingPhase")],_);return _}));
