/* COPYRIGHT Esri - https://js.arcgis.com/5.0.18/LICENSE.txt */
import{watch as e,syncAndInitial as t}from"../../../core/reactiveUtils.js";import{intersection as r}from"../../../core/SetUtils.js";import{sqlAnd as n}from"../../../core/sql.js";import{mergeTimeExtents as o}from"../../../core/timeUtils.js";import{squaredDistance as i}from"../../../core/libs/gl-matrix-2/math/vec3.js";import{makeDehydratedPoint as s}from"../../../layers/graphics/dehydratedPoint.js";import a from"../../../rest/support/Query.js";import{ViewEventPriorities as l}from"../../input/InputManager.js";import{snappingKeys as p}from"../keybindings.js";import{fromAnyMapPoint as c}from"../sketch/normalizedPoint.js";import{isWebMap as m}from"../../../webmap/utils.js";const g=Symbol("grid-placement-graphic");function u(e,t){const r=e.length===t.length&&e[0]===t[0]&&e[1]===t[1];switch(e.length){case 2:return r;case 3:return r&&e[2]===t[2];case 4:return r&&e[2]===t[2]&&e[3]===t[3]}return!1}function d(e,t){const r=e.x-t.x,n=e.y-t.y;return r*r+n*n}function f(e,t){return Math.sqrt(d(e,t))}function y(e,t){t.sort((t,r)=>i(t.targetPoint,e)-i(r.targetPoint,e))}function h({parameters:{point:e,distance:t,returnEdge:r,vertexMode:i,coordinateHelper:{spatialReference:l},filter:p},returnZ:c,filter:m}){const g=m?.clone()??new a({where:"1=1"});return g.returnZ=c,p&&(g.geometry=p.geometry,g.distance=p.distance,g.spatialRelationship=p.spatialRelationship,g.where=n(g.where,p.where),g.timeExtent=o(g.timeExtent,p.timeExtent),g.objectIds=w(g.objectIds,p.objectIds)),{point:s(e[0],e[1],e[2],l.toJSON()),distance:t,returnEdge:r,vertexMode:i,query:g.toJSON()}}function w(e,t){return e||t?t?e?Array.from(r(new Set(e),new Set(t))):t:e:null}function j(e,t,r){return{left:c(e.leftVertex.pos,t,r),right:c(e.rightVertex.pos,t,r)}}const b=Symbol("snapping-toggle");function x(r,n=()=>{}){const o=e(()=>({view:r.view,snappingOptions:r.snappingOptions}),({view:e,snappingOptions:t})=>{if(r.removeHandles(b),!e||!t)return;const o=l.TOOL,i=[e.on("key-down",e=>{e.key!==p.toggle||e.repeat||(t.enabledToggled=!0,n())},o),e.on("key-up",e=>{e.key===p.toggle&&(t.enabledToggled=!1,n())},o),e.on("pointer-move",e=>{const r=e.native.ctrlKey;t.enabledToggled!==r&&(t.enabledToggled=r,n())},o)];r.addHandles(i,b)},t);r.addHandles(o)}function v(e){return m(e)&&"utilityNetworks"in e&&!!e.utilityNetworks?.length}function k(e){return"line"===e?.type}export{j as editEdgeToSnappingEdge,g as gridPlacementGraphicSymbol,k as isLine,v as isUtilityNetworkWebMap,h as makeSnappingQuery,u as objectEqual,f as screenDistance,x as setupSnappingToggleHandles,y as sortCandidatesInPlace,d as squaredScreenDistance};
