/* COPYRIGHT Esri - https://js.arcgis.com/5.2/LICENSE.txt */
import{__decorate as t}from"tslib";import e from"../../../../analysis/LineOfSightAnalysisTarget.js";import{destroyMaybe as i}from"../../../../core/maybe.js";import{watch as s,sync as o}from"../../../../core/reactiveUtils.js";import{property as n,subclass as r}from"../../../../core/accessorSupport/decorators.js";import{updateLineOfSightItemFromIntersection as a,updateLineOfSightItemFromAuthoredPoint as l}from"./LineOfSightAuthoringUtils.js";import{LineOfSightRayIntersector as u}from"./LineOfSightRayIntersector.js";import{PluginBase as p}from"../../../draw/plugins/PluginBase.js";var c;const d=Symbol("line-of-sight-target-vertex"),h=Symbol("line-of-sight-target-plugin-marker");let v=class extends p{constructor(){super(...arguments),this[c]=!0,this.target=null,this.defaultElevationInfo=null,this.defaultCaptureMode="capture-always",this.inputMapPosition=null,this.preservedIntersection=null,this.sourceElevationInfo=null,this._interactiveHandle=null,this._intersector=null}static{c=h}initialize(){this._intersector=new u({view:this.view})}destroy(){this._intersector=i(this._intersector)}get usesSnappedAbsoluteHeight(){const t=this._interactiveHandle,e=t?.inputMapPosition,i=t?.outputMapPosition;return null!=e&&null!=i&&!e.equals(i)}start(t){super.start(t),this.preservedIntersection=null;const{positionOfLastUserInput:n,session:r}=t,u="grabbable-object"===this.defaultCaptureMode?this.inputMapPosition??this._interactiveHandle?.outputMapPosition??n:this.inputMapPosition??n;!u||"grabbable-object"!==this.defaultCaptureMode&&this._interactiveHandle||r.appendOrReplacePoint(d,u);let p="capture-always"===this.defaultCaptureMode&&null!=u;this._interactiveHandle&&this._clearCursorTarget(),this._interactiveHandle||(this._interactiveHandle=t.createInteractiveHandle({defaultCaptureMode:this.defaultCaptureMode,inputMapPosition:"grabbable-object"===this.defaultCaptureMode?u??void 0:void 0}),this.addHandles(s(()=>this._interactiveHandle?.outputMapPosition,t=>{if(!t||this._isComplete)return;const s=this.analysisViewData.cursorTarget??new e,o=this.usesSnappedAbsoluteHeight,n=this._interactiveHandle?.screenPosition,r=n&&this._intersector?this._intersector.getScreenPointIntersection(n):null;return this._session?.appendOrReplacePoint(d,t),p?(p=!1,void this._clearCursorTarget()):null!=r?(this.analysisViewData.cursorTarget=s,void a(this.view,s,r,{snappedMapPoint:t,defaultElevationInfo:this.defaultElevationInfo,sourceElevationInfo:this.sourceElevationInfo,useSnappedAbsoluteHeight:o})):null!=n&&null!=this.preservedIntersection?(this.analysisViewData.cursorTarget=s,void a(this.view,s,this.preservedIntersection,{snappedMapPoint:t,defaultElevationInfo:this.defaultElevationInfo,sourceElevationInfo:this.sourceElevationInfo,useSnappedAbsoluteHeight:o})):void(null==n&&this._intersector&&l(this.view,s,this._intersector,t,{defaultElevationInfo:this.defaultElevationInfo,sourceElevationInfo:this.sourceElevationInfo,preservedIntersection:this.preservedIntersection,useSnappedAbsoluteHeight:o,preferPreservedIntersection:!0})?this.analysisViewData.cursorTarget=s:this.analysisViewData.cursorTarget=i(this.analysisViewData.cursorTarget))},o),this._ownHandlesKey))}complete(){this._clearCursorTarget(),super.complete()}cancel(){this._clearCursorTarget()}_clearCursorTarget(){this.analysisViewData.cursorTarget=i(this.analysisViewData.cursorTarget)}};function f(t){return!!t&&h in t}function g(t){return{uniqueId:Symbol("line-of-sight-target-plugin"),kind:["vertex"],geometryType:"point",hidden:!0,localizationKey:"leaf-point-segment",icon:"point",create:()=>new v(t)}}t([n({constructOnly:!0})],v.prototype,"analysis",void 0),t([n({constructOnly:!0})],v.prototype,"analysisViewData",void 0),t([n({constructOnly:!0})],v.prototype,"view",void 0),t([n({constructOnly:!0})],v.prototype,"target",void 0),t([n({constructOnly:!0})],v.prototype,"defaultElevationInfo",void 0),t([n()],v.prototype,"defaultCaptureMode",void 0),t([n()],v.prototype,"inputMapPosition",void 0),t([n()],v.prototype,"preservedIntersection",void 0),t([n({constructOnly:!0})],v.prototype,"sourceElevationInfo",void 0),t([n()],v.prototype,"_interactiveHandle",void 0),t([n()],v.prototype,"_intersector",void 0),v=t([r("esri.views.3d.analysis.LineOfSight.LineOfSightTargetPlugin")],v);export{v as LineOfSightTargetPlugin,g as createLineOfSightTargetPluginConfiguration,f as isLineOfSightTargetPlugin,h as lineOfSightTargetPluginMarker};
