/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
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{SketchHandlerMixin as s}from"../../mixins/SketchHandlerMixin.js";import{mapSpaceToImageSpace as c}from"../../support/dataCaptureUtils.js";let p=class extends(s(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:p,oiObjectIdField:n,activeViewer:l,mode:h},pendingGraphics:u}=this,m=l?.imageSize;c&&p&&o&&n&&s&&m&&"none"!==h&&"video"!==h&&"panoramic-video"!==h&&(d(i,a,p,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 d(e,t,r,a,o,s,p,d,n,l){e.origin=l,e.attributes=e.attributes??{},e.attributes[r]=btoa(JSON.stringify({geometry:c(t.clone(),n,d).toJSON()})),e.attributes[a]=o.attributes.objectId,s.has(p)||s.set(p,new i);s.get(p).add(e)}function n(e,t){return e.map(({attributes:e})=>t?e[t]:null).filter(Boolean)}e([a()],p.prototype,"collectionId",null),e([a()],p.prototype,"savedGraphics",void 0),e([a()],p.prototype,"type",void 0),e([a()],p.prototype,"pendingGraphics",void 0),p=e([o("esri.widgets.OrientedImageryViewer.adapters.sketch.DataCaptureAdapter")],p);const l=p;export{l as default};
