/*
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/Accessor","../../core/HandleOwner","../../core/handleUtils","../../core/maybe","../../core/reactiveUtils","../../core/accessorSupport/decorators/aliasOf","../../core/arrayUtils","../../core/has","../../core/accessorSupport/ensureType","../../core/accessorSupport/decorators/property","../../core/accessorSupport/decorators/subclass"],(function(e,i,t,r,s,o,n,a,l,p,c,u,d){"use strict";const y=["visibility"];let h=function(i){function t(e){var t;return(t=i.call(this,e)||this)._expressionTrackingHandles=new Map,t.arcade=null,t.visibilityExpression=null,t.description=null,t.expressionTrackingProvider={registerExpression:()=>s.makeHandle()},t.feature=null,t.groupElement=null,t.label=null,t.spatialReference=null,t}e._inheritsLoose(t,i);var r=t.prototype;return r.initialize=function(){this.own(y.map((e=>n.watch((()=>this.get(`${e}Function`)),(i=>{o.isSome(i)?this._registerExpressionWithTrackingProvider(e):this._unregisterExpressionWithTrackingProvider(e)}),n.syncAndInitial))))},r._registerExpressionWithTrackingProvider=function(e){const{_expressionTrackingHandles:i}=this;if(i.has(e))return;const t=`evaluated${_(e)}Expression`,r=this.expressionTrackingProvider.registerExpression((()=>this.notifyChange(t)));i.set(e,r)},r._unregisterExpressionWithTrackingProvider=function(e){const{_expressionTrackingHandles:i}=this,t=i.get(e);t&&(t.remove(),i.delete(e))},r._dirtyEvaluatedVisibilityExpression=function(){const{groupElement:e}=this;o.isSome(e)&&e.visibilityExpression&&this.notifyChange("evaluatedVisibilityExpression")},e._createClass(t,[{key:"visibilityFunction",set:function(e){this._set("visibilityFunction",e),o.isSome(e)?this._registerExpressionWithTrackingProvider("visibility"):this._unregisterExpressionWithTrackingProvider("visibility")}},{key:"evaluatedVisibilityExpression",get:function(){const{visibilityFunction:e,spatialReference:i}=this;if(o.isNone(e))return;const{arcade:t}=this,r=t.arcadeUtils.getViewInfo({spatialReference:o.unwrap(i)});return t.arcadeUtils.executeFunction(e,t.arcadeUtils.createExecContext(this.feature,r))}},{key:"inputFields",get:function(){return this._get("inputFields")},set:function(e){this.handles.removeAll(),e&&this.handles.add(e.map((e=>n.watch((()=>e.visible),(()=>this._dirtyEvaluatedVisibilityExpression()))))),this._set("inputFields",e)}},{key:"state",get:function(){return o.isSome(this.groupElement)&&this.groupElement.initialState||"expanded"},set:function(e){o.isNone(e)?this._clearOverride("state"):this._override("state",e)}},{key:"visible",get:function(){return!1!==this.evaluatedVisibilityExpression&&this.inputFields&&this.inputFields.some((e=>e.visible))}}]),t}(r.HandleOwnerMixin(t));i.__decorate([u.property()],h.prototype,"arcade",void 0),i.__decorate([a.aliasOf("groupElement.visibilityExpression")],h.prototype,"visibilityExpression",void 0),i.__decorate([u.property()],h.prototype,"visibilityFunction",null),i.__decorate([u.property()],h.prototype,"evaluatedVisibilityExpression",null),i.__decorate([a.aliasOf("groupElement.description")],h.prototype,"description",void 0),i.__decorate([u.property()],h.prototype,"expressionTrackingProvider",void 0),i.__decorate([u.property()],h.prototype,"feature",void 0),i.__decorate([u.property()],h.prototype,"groupElement",void 0),i.__decorate([u.property()],h.prototype,"inputFields",null),i.__decorate([a.aliasOf("groupElement.label")],h.prototype,"label",void 0),i.__decorate([u.property()],h.prototype,"spatialReference",void 0),i.__decorate([u.property()],h.prototype,"state",null),i.__decorate([u.property()],h.prototype,"visible",null),h=i.__decorate([d.subclass("esri.widgets.FeatureForm.InputFieldGroup")],h);const _=e=>e.charAt(0).toUpperCase()+e.slice(1);return h}));
