/*
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 r from"../../../core/Accessor.js";import i from"../../../core/Error.js";import{watch as t,initial as n}from"../../../core/reactiveUtils.js";import{property as a,subclass as s}from"../../../core/accessorSupport/decorators.js";import o from"../../../views/interactive/snapping/FeatureSnappingLayerSource.js";import l from"../../../views/interactive/snapping/SnappingOptions.js";import{canDisplayLayer as p}from"../../LayerList/support/layerListUtils.js";import{SnappingLayerListViewModel as d}from"./SnappingLayerListViewModel.js";let y=class extends r{constructor(e){super(e),this.layerListViewModel=new d,this.snappingOptions=new l,this.view=null}initialize(){this.addHandles([t(()=>({viewModel:this.layerListViewModel,view:this.view}),({viewModel:e,view:r})=>{e.view=r},n),t(()=>({viewModel:this.layerListViewModel,sources:this.snappingOptions?.featureSources}),({viewModel:e,sources:r})=>{e.featureSnappingSources=r},n)])}get allLayersEnabled(){return(this.layerListViewModel?.selectableItems??[]).every(e=>"enabled"===e.enabled)}get allLayersDisabled(){return(this.layerListViewModel?.selectableItems??[]).every(e=>!e.enabled)}get layersEnabledCount(){return this.layerListViewModel?.selectableItems?.filter(e=>"enabled"===e.enabled).length??0}get state(){return this.snappingOptions?"ready":"disabled"}toggleSnappingForLayers(e,r){e?.forEach(e=>r?this.enableSnappingForLayer(e):this.disableSnappingForLayer(e))}toggleSnappingForAllLayers(e){this.layerListViewModel.selectableItems.forEach(({layer:r})=>{const i=r?.id;e?this.enableSnappingForLayer(i):this.disableSnappingForLayer(i)})}enableSnappingForLayer(e){const r=this._findSnappingSourceForLayer(e)??this._makeSnappingSourceForLayer(e);r&&(r.enabled=!0)}disableSnappingForLayer(e){const r=this._findSnappingSourceForLayer(e);r&&(r.enabled=!1)}updateEnabledFeatureSources(e){for(const r of this.snappingOptions.featureSources)p(r.layer)&&(r.enabled=e.includes(r.layer.id))}_findSnappingSourceForLayer(e){return this.snappingOptions.featureSources.find(r=>r.layer.id===e)}_makeSnappingSourceForLayer(e){const r=this.layerListViewModel.operationalItemsFlat.find(r=>r.layer?.id===e)?.layer;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`);if("group"===r.type)return;const t=new o({layer:r});return this.snappingOptions.featureSources.add(t),t}};e([a()],y.prototype,"allLayersEnabled",null),e([a()],y.prototype,"allLayersDisabled",null),e([a({constructOnly:!0})],y.prototype,"layerListViewModel",void 0),e([a()],y.prototype,"layersEnabledCount",null),e([a({type:l,nonNullable:!0})],y.prototype,"snappingOptions",void 0),e([a()],y.prototype,"state",null),e([a()],y.prototype,"view",void 0),y=e([s("esri.widgets.support.SnappingControls.SnappingControlsViewModel")],y);const u=y;export{u as default};
