/* COPYRIGHT Esri - https://js.arcgis.com/5.0.18/LICENSE.txt */
import{__decorate as e}from"tslib";import t from"../WebLinkChart.js";import r from"../core/Collection.js";import i from"../core/Error.js";import{watch as a}from"../core/reactiveUtils.js";import{property as o,subclass as s}from"../core/accessorSupport/decorators.js";import{project as n}from"../geometry/projectionUtils.js";import p from"../geometry/SpatialReference.js";import{MeasuredGrid as c}from"../grids/MeasuredGrid.js";import{startNodeMovement as h}from"../layers/knowledgeGraph/nodeMovementUtils.js";import d from"./View2D.js";import g from"./interactive/snapping/FeatureSnappingLayerSource.js";import{SnappingManager as l}from"./interactive/snapping/SnappingManager.js";import m from"./interactive/snapping/SnappingOptions.js";import u from"../webmap/background/ColorBackground.js";let y=class extends d{constructor(e){super(e),this.map=null,this.view2dType="linkchart",this._isReshapeActive=!1,this._previousGridSettings=void 0,this._cachedSnappingManager=void 0;const t=e=>{this.spatialReference="geographic-organic-standard"===e?this.map.basemap?.spatialReference??p.WebMercator:p.WGS84};let r=null;this.addHandles(a(()=>this.map,e=>{e&&(r&&r.remove(),r=a(()=>e.linkChartProperties.layoutType,t),this.addHandles(r))},{initial:!0}))}get background(){return this.map?.initialViewProperties.background??new u({color:[255,255,255,1]})}set background(e){this._override("background",e)}get inGeographicLayout(){return"geographic-organic-standard"===this.map?.linkChartProperties.layoutType}async startNodeMovement(e,t,a){if(this._isReshapeActive)throw new i("LinkChartView:reshape-already-active","Node movement reshape is already active");this._isReshapeActive=!0;const o=new r;for(const r of this.map?.activeLinkChartLayer?.layers??[])if("relationship"===r.graphType){const e=new g({layer:r});o.add(e)}try{let r;a?.useSnappingGrid&&(this._previousGridSettings=this.grid,this.grid||(this.grid=new c({units:"feet",center:this.center,rotateWithMap:!0})),this._cachedSnappingManager?(r=this._cachedSnappingManager,r.options.gridEnabled=a?.useSnappingGrid):(r=new l({options:new m({enabled:!0,featureSources:o,gridEnabled:a?.useSnappingGrid}),view:this}),this._cachedSnappingManager=r));const s=await h({targetEntityId:e,targetEntityType:t,view:this,snappingManager:r});return{commitNodeMovement:async()=>{if(!this._isReshapeActive)throw new i("LinkChartView:reshape-not-active","Node movement reshape is not active");this._isReshapeActive=!1;const t=s.currentReshapeGraphic.sourceLayer?.parent,r=t.getCurrentNodeLocations(),a=n(s.currentReshapeGraphic.geometry,{wkid:4326});return r.set(e,a),await t.applyNewLinkChartLayout(this.map.activeLinkChartLayer?.getCurrentLayout(),{lockedEntityLocations:r}),s.teardownHandle.remove(),this.grid=this._previousGridSettings,a},cancelNodeMovement:()=>{if(!this._isReshapeActive)return;this._isReshapeActive=!1;const e=[];for(const t of s.localEdits.values())t.graphic.geometry=void 0,"knowledge-graph-sublayer"===t.graphic.sourceLayer?.type&&"relationship"===t.graphic.sourceLayer?.graphType&&(t.graphic.sourceLayer.parent.relationshipLinkChartDiagramLookup.set(t.graphic.attributes.ESRI__ID,s.originalRelationshipGeometries.get(t.graphic.attributes.ESRI__ID)??null),e.push(t.graphic.sourceLayer));for(const t of e)t.refreshCachedQueryEngine().then(()=>{t?.emit("refresh",{dataChanged:!0})});s.teardownHandle.remove(),this.grid=this._previousGridSettings}}}catch(s){throw this._isReshapeActive=!1,s}}};e([o({type:u})],y.prototype,"background",null),e([o()],y.prototype,"inGeographicLayout",null),e([o({type:t})],y.prototype,"map",void 0),e([o({readOnly:!0})],y.prototype,"view2dType",void 0),y=e([s("esri.views.LinkChartView")],y);const v=y;export{v as default};
