/*
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 t from"../../../../core/Accessor.js";import i from"../../../../core/Collection.js";import r from"../../../../core/ReactiveMap.js";import{property as a,subclass as o}from"../../../../core/accessorSupport/decorators.js";import{mapSpaceToImageSpace as s}from"../../dataCaptureUtils.js";import{SketchHandlerMixin as c}from"../../mixins/SketchHandlerMixin.js";let d=class extends(c(t)){constructor(e){super(e),this.savedGraphics=new i,this.type="data-capture",this.pendingGraphics=new r}get collectionId(){return this.viewModel.collectionId}handleCreate(e){const{state:t,graphic:i,tool:r}=e,a=i?.geometry;if("complete"!==t||!i||!a)return;const{collectionId:o,viewModel:{dataCaptureLayer:s,currentBestFeature:c,imageGeometryField:d,oiObjectIdField:n,activeViewer:l,mode:h},pendingGraphics:u}=this,m=l?.imageSize;c&&d&&o&&n&&s&&m&&"none"!==h&&"video"!==h&&"panoramic-video"!==h&&(p(i,a,d,n,c,u,o,m,h,s),this.viewModel.emit("after-data-capture-complete",{pendingGraphics:u.get(o)?.toArray()??null}),this.viewModel.sketch?.create(r))}handleDelete(e){const{dataCaptureLayer:t}=this.viewModel;if(!t)return;const{graphics:i}=e;this.pendingGraphics.get(t.id)?.removeMany(i),this.savedGraphics.removeMany(i),this.viewModel.deleteDataCaptureFeatures(n(i,t.objectIdField))}handleDestroy(){const{dataCaptureLayer:e}=this.viewModel;e&&(this.viewModel.stopDataCapture(),this.savedGraphics.removeAll(),this.pendingGraphics=null)}handleUpdate(e){const{toolEventInfo:t,state:i,graphics:r}=e;if(t)this.viewModel.sketch?.undo();else switch(i){case"complete":this.viewModel.emit("deselect-data-capture-features",{graphics:r});break;case"start":this.viewModel.emit("select-data-capture-features",{graphics:r})}}};function p(e,t,r,a,o,c,d,p,n,l){e.sourceLayer=l,e.attributes=e.attributes??{},e.attributes[r]=btoa(JSON.stringify({geometry:s(t.clone(),n,p).toJSON()})),e.attributes[a]=o.attributes.objectId,c.has(d)||c.set(d,new i);c.get(d).add(e)}function n(e,t){return e.map(({attributes:e})=>t?e[t]:null).filter(Boolean)}e([a()],d.prototype,"collectionId",null),e([a()],d.prototype,"savedGraphics",void 0),e([a()],d.prototype,"type",void 0),e([a()],d.prototype,"pendingGraphics",void 0),d=e([o("esri.widgets.OrientedImageryViewer.adapters.sketch.DataCaptureAdapter")],d);const l=d;export{l as default};
