/* COPYRIGHT Esri - https://js.arcgis.com/5.0.18/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{extractHorizonAnglesFromMedia as s}from"../../utils.js";import{SketchHandlerMixin as c}from"../../mixins/SketchHandlerMixin.js";import{mapSpaceToImageSpace as p}from"../../support/dataCaptureUtils.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:c,currentBestFeature:p,imageGeometryField:d,oiObjectIdField:l,activeViewer:h,mode:u},pendingGraphics:m}=this,g=h?.imageSize,v=h?.media;if(!(p&&d&&o&&l&&c&&g&&("default"===u||"panoramic"===u)))return;n(i,a,d,l,p,m,o,g,u,c,s(v)),this.viewModel.emit("after-data-capture-complete",{pendingGraphics:m.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(l(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 n(e,t,r,a,o,s,c,d,n,l,h){e.origin=l?.graphicOrigin??l,e.attributes=e.attributes??{},e.attributes[r]=btoa(JSON.stringify({geometry:p(t.clone(),n,d,h).toJSON()})),e.attributes[a]=o.attributes.objectId,s.has(c)||s.set(c,new i);s.get(c).add(e)}function l(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 h=d;export{h as default};
