/* COPYRIGHT Esri - https://js.arcgis.com/5.0.18/LICENSE.txt */
import{__decorate as e}from"tslib";import{watch as t,initial as i}from"../../core/reactiveUtils.js";import{property as o,subclass as n}from"../../core/accessorSupport/decorators.js";import s from"../Widget.js";import r from"./FeatureContent.js";import d from"./FeatureFields.js";import l from"./FeatureMedia.js";import a from"./FeatureExpression/FeatureExpressionViewModel.js";import{loadCalciteComponents as c}from"../support/componentsUtils.js";import{tsx as p}from"../support/widget.js";const m="esri-feature",u={base:`${m}-expression`,loadingSpinnerContainer:`${m}__loading-container`};let g=class extends s{constructor(e,t){super(e,t),this._contentWidget=null,this.viewModel=new a}initialize(){this.addHandles(t(()=>this.viewModel?.contentElementViewModel,()=>this._setupExpressionWidget(),i))}loadDependencies(){return c({loader:()=>import("@esri/calcite-components/dist/components/calcite-loader")})}destroy(){this._destroyContentWidget()}render(){const{state:e}=this.viewModel;return p("div",{class:u.base},"loading"===e?this._renderLoading():"disabled"===e?null:this._contentWidget?.render())}_renderLoading(){return p("div",{class:u.loadingSpinnerContainer,key:"loading-container"},p("calcite-loader",{inline:!0,label:""}))}_destroyContentWidget(){const{_contentWidget:e}=this;e&&(e.viewModel=null,e.destroy()),this._contentWidget=null}_setupExpressionWidget(){const{contentElementViewModel:e,contentElement:t}=this.viewModel,i=t?.type;this._destroyContentWidget();const o=e?"fields"===i?new d({viewModel:e}):"media"===i?new l({viewModel:e}):"text"===i?new r({viewModel:e}):null:null;this._contentWidget=o,this.scheduleRender()}};e([o({type:a})],g.prototype,"viewModel",void 0),g=e([n("esri.widgets.Feature.FeatureExpression")],g);export{g as default};
