/* COPYRIGHT Esri - https://js.arcgis.com/5.0.18/LICENSE.txt */
import{__decorate as t}from"tslib";import o from"../../../core/Accessor.js";import{isSome as e}from"../../../core/arrayUtils.js";import i from"../../../core/Collection.js";import{watch as r,initial as s}from"../../../core/reactiveUtils.js";import{property as n,subclass as d}from"../../../core/accessorSupport/decorators.js";import l from"../FilterCondition.js";import{defaultOperatorNamesByFieldType as a}from"../FilterCondition/conditionUtils.js";let p=class extends o{constructor(t){super(t),this.conditionOperator="AND",this.conditionWidgets=new i,this.layer=null,this.operators=a}initialize(){this.addHandles([r(()=>this.layer,async t=>{t&&!t.loaded&&await t.load()},s)])}get count(){return this.conditionWidgets.length}get state(){const{layer:t}=this;return t?t.loaded?"ready":"loading":"disabled"}get whereClause(){const{conditionOperator:t,whereClauses:o}=this;let e="";return o.forEach((o,i)=>{e+=i>0?` ${t} (${o})`:`(${o})`}),e}get whereClauses(){return this.conditionWidgets.toArray().map(t=>t.whereClause).filter(e)}addCondition(t,o){const{layer:e,operators:i}=this;e&&this.conditionWidgets.add(new l({...t,layer:e,operators:i}),o)}duplicateCondition(t){const o=this.conditionWidgets.at(t);if(!o)return;const{fieldName:e,operator:i,value:r}=o;this.addCondition({fieldName:e,operator:i,value:r})}reset(){this.conditionWidgets.removeAll()}removeCondition(t){null==t?this.conditionWidgets.pop():this.conditionWidgets.splice(t,1)}};t([n()],p.prototype,"conditionOperator",void 0),t([n()],p.prototype,"conditionWidgets",void 0),t([n()],p.prototype,"count",null),t([n()],p.prototype,"layer",void 0),t([n()],p.prototype,"operators",void 0),t([n()],p.prototype,"state",null),t([n()],p.prototype,"whereClause",null),t([n()],p.prototype,"whereClauses",null),p=t([d("esri.widgets.support.FilterBuilder.FilterBuilderViewModel")],p);export{p as default};
