/*
All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
*/
import{__decorate as e}from"tslib";import{property as t,cast as o,subclass as i}from"../../core/accessorSupport/decorators.js";import r from"../Widget.js";import{loadCalciteComponents as n}from"./componentsUtils.js";import{tsx as s,messageBundle as l}from"./widget.js";import c from"./FilterBuilder/FilterBuilderViewModel.js";const a={fab:!0,menu:!0},d="esri-filter-builder",p={base:d,conditionContainer:`${d}__condition-container`,operatorSelect:`${d}__operator-select`};let u=class extends r{constructor(e,t){super(e,t),this.messages=null,this.messagesCommon=null,this.viewModel=new c,this.visibleElements={...a}}loadDependencies(){return n({action:()=>import("@esri/calcite-components/dist/components/calcite-action"),"action-menu":()=>import("@esri/calcite-components/dist/components/calcite-action-menu"),block:()=>import("@esri/calcite-components/dist/components/calcite-block"),fab:()=>import("@esri/calcite-components/dist/components/calcite-fab"),option:()=>import("@esri/calcite-components/dist/components/calcite-option"),select:()=>import("@esri/calcite-components/dist/components/calcite-select")})}get conditionOperator(){return this.viewModel.conditionOperator}set conditionOperator(e){this.viewModel.conditionOperator=e}get count(){return this.viewModel.count}get layer(){return this.viewModel.layer}set layer(e){this.viewModel.layer=e}get operators(){return this.viewModel.operators}set operators(e){this.viewModel.operators=e}get state(){return this.viewModel.state}castVisibleElements(e){return{...a,...e}}get whereClause(){return this.viewModel.whereClause}get whereClauses(){return this.viewModel.whereClauses}render(){return s("div",{class:p.base},this._renderOperatorSelect(),this._renderConditions(),this._renderFAB())}reset(){this.viewModel.reset()}_renderOperatorSelect(){if(this.count<2)return;const{conditionOperator:e,messages:t}=this,o="AND"===e;return s("div",{class:p.operatorSelect},s("calcite-select",{label:t.condition,width:"full",onCalciteSelectChange:({currentTarget:e})=>{this.conditionOperator=e.value}},s("calcite-option",{label:t.allAreTrue,selected:o,value:"AND"}),s("calcite-option",{label:t.anyAreTrue,selected:!o,value:"OR"})))}_renderConditions(){return this.viewModel.conditionWidgets.toArray().map((e,t)=>this._renderConditionContainer(e,t))}_renderConditionContainer(e,t){return s("calcite-block",{class:p.conditionContainer,expanded:!0,heading:this.messages.condition},e.render(),this._renderConditionrMenu(t))}_renderFAB(){if(!this.visibleElements.fab)return;const e="loading"===this.state;return s("calcite-fab",{appearance:"outline-fill",disabled:e,icon:"plus",kind:"neutral",loading:e,onclick:()=>this.viewModel.addCondition(),text:this.messages.addNew,textEnabled:!0})}_renderConditionrMenu(e){if(!this.visibleElements.menu)return;const{messages:t}=this;return s("calcite-action-menu",{label:t.moreOptions,overlayPositioning:"fixed",placement:"bottom-end",slot:"control"},s("calcite-action",{onclick:()=>this.viewModel.removeCondition(e),text:t.delete,textEnabled:!0}),s("calcite-action",{onclick:()=>this.viewModel.duplicateCondition(e),text:t.duplicate,textEnabled:!0}))}};e([t()],u.prototype,"conditionOperator",null),e([t()],u.prototype,"count",null),e([t()],u.prototype,"layer",null),e([t(),l("esri/widgets/support/FilterBuilder/t9n/FilterBuilder")],u.prototype,"messages",void 0),e([t(),l("esri/t9n/common")],u.prototype,"messagesCommon",void 0),e([t()],u.prototype,"operators",null),e([t()],u.prototype,"state",null),e([t()],u.prototype,"viewModel",void 0),e([t()],u.prototype,"visibleElements",void 0),e([o("visibleElements")],u.prototype,"castVisibleElements",null),e([t()],u.prototype,"whereClause",null),e([t()],u.prototype,"whereClauses",null),u=e([i("esri.widgets.support.FilterBuilder")],u);export{u as default};
