/*
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/Error","../../../core/HandleOwner","../../../core/reactiveUtils","../../../core/accessorSupport/decorators/property","../../../core/arrayUtils","../../../core/has","../../../core/accessorSupport/ensureType","../../../core/accessorSupport/decorators/subclass","../../../views/interactive/snapping/FeatureSnappingLayerSource","../../LayerList/support/layerListUtils","./SnappingLayerListViewModel"],(function(e,r,n,i,t,o,a,s,p,c,l,u,d,y){"use strict";const w="esri.widgets.support.SnappingControls.SnappingControlsViewModel";let S=function(r){function n(e){var n;return(n=r.call(this,e)||this).layerListViewModel=new y.SnappingLayerListViewModel,n.snappingOptions=null,n.view=null,n}e._inheritsLoose(n,r);var t=n.prototype;return t.initialize=function(){this.handles.add([o.watch((()=>({viewModel:this.layerListViewModel,view:this.view})),(({viewModel:e,view:r})=>{e.view=r}),o.initial),o.watch((()=>{var e;return{viewModel:this.layerListViewModel,sources:null==(e=this.snappingOptions)?void 0:e.featureSources}}),(({viewModel:e,sources:r})=>{e.featureSnappingSources=r}),o.initial)])},t.enableSnappingForLayer=function(e){var r;(null!=(r=this._findSnappingSourceForLayer(e))?r:this._makeSnappingSourceForLayer(e)).enabled=!0},t.disableSnappingForLayer=function(e){const r=this._findSnappingSourceForLayer(e);r&&(r.enabled=!1)},t.updateEnabledFeatureSources=function(e){for(const r of this.snappingOptions.featureSources)d.canDisplayLayer(r.layer)&&(r.enabled=e.includes(r.layer.id))},t._findSnappingSourceForLayer=function(e){return this.snappingOptions.featureSources.find((r=>r.layer.id===e))},t._makeSnappingSourceForLayer=function(e){const{layer:r}=this.layerListViewModel.operationalItemsFlat.find((r=>r.layer.id===e));if(!r)throw new i("snapping-controls:layer-not-found",`cannot enable snapping for layer with id ${e} because no such layer was found in the view`);const n=new u({layer:r});return this.snappingOptions.featureSources.add(n),n},e._createClass(n,[{key:"state",get:function(){return this.get("snappingOptions")?"ready":"disabled"}}]),n}(t.HandleOwnerMixin(n));r.__decorate([a.property({constructOnly:!0})],S.prototype,"layerListViewModel",void 0),r.__decorate([a.property({constructOnly:!0})],S.prototype,"snappingOptions",void 0),r.__decorate([a.property()],S.prototype,"state",null),r.__decorate([a.property({constructOnly:!0})],S.prototype,"view",void 0),S=r.__decorate([l.subclass(w)],S);return S}));
