/* COPYRIGHT Esri - https://js.arcgis.com/5.2/LICENSE.txt */
import{destroyHandle as e}from"../../../../core/handleUtils.js";import{watch as n,sync as r,initial as t}from"../../../../core/reactiveUtils.js";import{createScreenPointArray as o}from"../../../../core/screenUtils.js";import{absoluteHeightElevationInfo as i}from"../../../../support/elevationInfoUtils.js";import{ViewshedDrawToolRenderer as s}from"./ViewshedDrawToolRenderer.js";import{isValidIntersectorResult as a}from"../../webgl-engine/lib/IntersectorResult.js";import{toGraphic as l}from"../../webgl-engine/lib/intersectorUtilsConversions.js";import{DrawTool as c}from"../../../draw/DrawTool.js";import{newToolIntersector as p}from"../../../interactive/ToolIntersector.js";import{acquire as d}from"../../../interactive/snapping/SnappingManagerPool.js";function m(o){const{analysisViewData:a,view:l,sketchOptions:m,onCancel:u,onComplete:g,onManipulatorCountChange:b,isPlacingObserver:j}=o,f=new s({view:l,isPlacingObserver:j}),v=d(l),w=p(l.state.viewingMode),{snappingManager:I}=v,M=new c({elevationInfo:i,enableVertexVisuals:!1,hasZ:!0,renderer:f,sketchOptions:m,snappingManager:I,view:l});return f.addObserverManipulator(M),M.addHandles([v,e(f),M.on("cancel",()=>u(M)),M.on("complete",()=>g(M)),n(()=>M.manipulators.length,()=>b(M),r),n(()=>a.visible,e=>f.analysisVisible=e,t)]),{drawTool:M,intersector:w,renderer:f,snappingManager:I}}function u({intersector:e,snappingManager:n,screenPoint:r,view:t}){const o=n.getMainFeatureCandidate();return o?b(o):r?g(r,t,e):null}function g(e,n,r){n.sceneIntersectionHelper.intersectToolIntersectorScreen(o(e.x,e.y),r);const t=r.results.min;return a(t)?l(t,n):null}function b(e){const n={id:e.layer.id,objectIdField:"objectIdField"in e.layer?e.layer.objectIdField:void 0};return{attributes:{[n.objectIdField??"ObjectId"]:e.objectId},layer:n,objectId:e.objectId,uid:null}}export{m as createDrawTool,u as getFeatureReference};
