/* COPYRIGHT Esri - https://js.arcgis.com/5.2/LICENSE.txt */
import{destroyHandle as e}from"../../../../core/handleUtils.js";import{watch as n,syncAndInitial as o}from"../../../../core/reactiveUtils.js";import{LineOfSightDrawToolRenderer as t}from"./LineOfSightDrawToolRenderer.js";import{isLineOfSightPlacementLeafPlugin as i}from"./LineOfSightPlacementLeafPlugin.js";import{LineOfSightRayIntersector as r}from"./LineOfSightRayIntersector.js";import{DrawTool as a}from"../../../draw/DrawTool.js";import s from"../../../interactive/sketch/SketchOptions.js";import{acquire as l}from"../../../interactive/snapping/SnappingManagerPool.js";import{createScreenPointFromEvent as p}from"../../../support/screenUtils.js";function c(c){const{analysisViewData:m,view:f,getVisible:g,getSourceElevationInfo:v,getSnapToSceneEnabled:d,onCancel:u,onComplete:w,onManipulatorCountChange:h}=c,S=v(),b=new t({view:f}),j=new r({view:f}),I=l(f),P=new a({elevationInfo:S,enableVertexVisuals:!1,hasZ:!0,renderer:b,sketchOptions:new s({tooltips:{enabled:!0}}),snappingManager:I.snappingManager,view:f});return b.elevationInfo=S,P.addHandles([I,e(b),e(j),P.on("cancel",()=>u(P)),P.on("complete",()=>w(P)),n(()=>[P.surfaceManager,d()],([e,n])=>{e&&(e.snapToSceneEnabled=n)},o),n(()=>[g(),m.visible,v()],([e,n,o])=>{P.visible=e&&n,P.elevationInfo=o,b.elevationInfo=o,b.refresh()},o),n(()=>P.manipulators.length,()=>h(P),o),P.on(["before-vertex-add","before-vertex-add-at-point"],e=>{const n=e.detail.originalEvent;if("immediate-click"!==n?.type)return;const o=p(n),t=j.getScreenPointIntersection(o);if(null==t?.mapPoint)e.preventDefault();else{const e=P.mostDownstreamPlugin;i(e)&&(e.preservedIntersection=t)}})]),{drawTool:P}}export{c as createDrawTool};
