/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
import{__decorate as e}from"tslib";import t from"../../../../core/Accessor.js";import r from"../../../../core/Collection.js";import i 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 r,this.type="data-capture",this.pendingGraphics=new i}get collectionId(){return this.viewModel.collectionId}handleCreate(e){const{state:t,graphic:r,tool:i}=e,a=r?.geometry;if("complete"!==t||!r||!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(r,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(i))}handleDelete(e){const{dataCaptureLayer:t}=this.viewModel;if(!t)return;const{graphics:r}=e;this.pendingGraphics.get(t.id)?.removeMany(r),this.savedGraphics.removeMany(r),this.viewModel.deleteDataCaptureFeatures(n(r,t.objectIdField))}handleDestroy(){const{dataCaptureLayer:e}=this.viewModel;e&&(this.viewModel.stopDataCapture(),this.savedGraphics.removeAll(),this.pendingGraphics=null)}handleUpdate(e){const{toolEventInfo:t,state:r,graphics:i}=e;if(t)this.viewModel.sketch?.undo();else switch(r){case"complete":this.viewModel.emit("deselect-data-capture-features",{graphics:i});break;case"start":this.viewModel.emit("select-data-capture-features",{graphics:i})}}};function d(e,t,i,a,o,s,p,d,n,l){e.sourceLayer=l,e.attributes=e.attributes??{},e.attributes[i]=btoa(JSON.stringify({geometry:c(t.clone(),n,d).toJSON()})),e.attributes[a]=o.attributes.objectId,s.has(p)||s.set(p,new r);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};
