/* COPYRIGHT Esri - https://js.arcgis.com/5.1.0/LICENSE.txt */
import{__decorate as t}from"tslib";import{IdentifiableMixin as e}from"../../core/Identifiable.js";import{ignoreAbortErrors as s}from"../../core/promiseUtils.js";import{watch as i,initial as o,on as a}from"../../core/reactiveUtils.js";import{property as r,subclass as n}from"../../core/accessorSupport/decorators.js";import{UpdatingHandles as l}from"../../core/support/UpdatingHandles.js";import{isAssociatedFeatureSupportedLayer as p}from"../../popup/support/featureUtils.js";import u from"./EditableInput.js";import c from"../support/UtilityNetworkAssociations/FeatureUtilityNetworkAssociationsViewModel.js";let d=class extends(e(u)){constructor(t){super(t),this.group=null,this.type="utilityNetworkAssociations",this.featureItem=null,this._updatingHandlesSetUp=new l,this.addHandles([i(()=>({feature:this.feature,element:this.element,layer:this.layer}),t=>this._createAssociationVM(t),o),i(()=>this.feature,()=>this._setFeatureItem()),i(()=>this.associatedLayer,(t,e)=>this._updateLayerEditHandle(t,e),o)])}destroy(){this._associationsVM?.destroy(),this._updatingHandlesSetUp.destroy()}get activeAssociationType(){return this._associationsVM?.activeAssociationType}get associatedFeatures(){const{associatedLayer:t}=this;if(t)return this.associatedFeatureInfos.get(t)}get associatedFeatureInfos(){const{_associationsVM:t}=this;if(!t?.associationFeatures?.size||!t?.utilityNetwork)return new Map;const{associationFeatures:e}=t,s=new Map;return e.forEach((t,e)=>{s.set(e,t)}),s}get associatedLayer(){return this._get("associatedLayer")}set associatedLayer(t){this._associationsVM.showAllEnabled=null!=t,this._set("associatedLayer",t)}get associationFeature(){return this.feature}get associationsViewModel(){return this._associationsVM}get canAddAssociation(){const{editable:t,utilityNetwork:e}=this;return!(!e||!this.loaded)&&t}get editable(){return this.evaluatedEditableExpression??!0}get featureCount(){return this._associationsVM?.featureCount??0}get viewModel(){return this._associationsVM}get loaded(){return"loading"!==this._associationsVM?.state&&!this._updatingHandlesSetUp.updating}get map(){return this._get("map")}set map(t){t&&this._associationsVM?.set("map",t),this._set("map",t)}get utilityNetwork(){return this._associationsVM?.utilityNetwork}get associationTypes(){return this._associationsVM?.associationTypes??this.element.associationTypes}get visible(){const{utilityNetwork:t}=this;return!!t&&(null!=this.evaluatedVisibilityExpression?this.evaluatedVisibilityExpression:null!=this.element)}get updating(){return"loading"===this._associationsVM?.state||"querying"===this._associationsVM?.state}async refresh(){await s(this._associationsVM.refresh())}_updateLayerEditHandle(t,e){e&&"layerId"in e&&this.removeHandles(e?.layerId),p(t)&&this.addHandles(a(()=>t,"edits",()=>this.refresh()),t.layerId)}_createAssociationVM(t){const{feature:e,element:s,layer:i}=t;if(this._associationsVM?.destroy(),!e||!s||!i)return;const{map:o,associationTypes:a}=this;p(i)&&(this._associationsVM=new c({graphic:e,layer:i,map:o,associationTypes:a,source:"featureForm",title:this.label,description:this.description}))}_setFeatureItem(){this._updatingHandlesSetUp.consumePromise((async()=>{const{feature:t,layer:e}=this;t&&e&&"getFeatureTitle"in e&&(this.featureItem={feature:t,label:await e.getFeatureTitle(t)})})())}};t([r()],d.prototype,"_associationsVM",void 0),t([r()],d.prototype,"activeAssociationType",null),t([r()],d.prototype,"associatedFeatures",null),t([r()],d.prototype,"associatedFeatureInfos",null),t([r()],d.prototype,"associatedLayer",null),t([r()],d.prototype,"associationFeature",null),t([r()],d.prototype,"associationsViewModel",null),t([r()],d.prototype,"canAddAssociation",null),t([r()],d.prototype,"editable",null),t([r()],d.prototype,"featureCount",null),t([r()],d.prototype,"viewModel",null),t([r()],d.prototype,"group",void 0),t([r()],d.prototype,"loaded",null),t([r()],d.prototype,"map",null),t([r()],d.prototype,"utilityNetwork",null),t([r()],d.prototype,"associationTypes",null),t([r({readOnly:!0})],d.prototype,"type",void 0),t([r()],d.prototype,"visible",null),t([r()],d.prototype,"updating",null),t([r()],d.prototype,"featureItem",void 0),d=t([n("esri.widgets.FeatureForm.UtilityNetworkAssociationInput")],d);const y=d;export{y as default};
