/* COPYRIGHT Esri - https://js.arcgis.com/5.2/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 c}from"../keybindings.js";import{fromAnyMapPoint as p}from"../sketch/normalizedPoint.js";import{isWebMap as m}from"../../../webmap/utils.js";export{screenDistance,squaredScreenDistance}from"../../../core/screenUtils.js";const g=Symbol("grid-placement-graphic");function d(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 u(e,t){t.sort((t,r)=>i(t.targetPoint,e)-i(r.targetPoint,e))}function f({parameters:{point:e,distance:t,returnEdge:r,vertexMode:i,coordinateHelper:{spatialReference:l},filter:c},returnZ:p,filter:m}){const g=m?.clone()??new a({where:"1=1"});return g.returnZ=p,c&&(g.geometry=c.geometry,g.distance=c.distance,g.spatialRelationship=c.spatialRelationship,g.where=n(g.where,c.where),g.timeExtent=o(g.timeExtent,c.timeExtent),g.objectIds=h(g.objectIds,c.objectIds)),{point:s(e[0],e[1],e[2],l.toJSON()),distance:t,returnEdge:r,vertexMode:i,query:g.toJSON()}}function h(e,t){return e||t?t?e?Array.from(r(new Set(e),new Set(t))):t:e:null}function y(e,t,r){return{left:p(e.leftVertex.pos,t,r),right:p(e.rightVertex.pos,t,r)}}const j=Symbol("snapping-toggle");function w(r,n=()=>{}){const o=e(()=>({view:r.view,snappingOptions:r.snappingOptions}),({view:e,snappingOptions:t})=>{if(r.removeHandles(j),!e||!t)return;const o=l.TOOL,i=[e.on("key-down",e=>{e.key!==c.toggle||e.repeat||(t.enabledToggled=!0,n())},o),e.on("key-up",e=>{e.key===c.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,j)},t);r.addHandles(o)}function b(e){return m(e)&&"utilityNetworks"in e&&!!e.utilityNetworks?.length}function v(e){return"line"===e?.type}export{y as editEdgeToSnappingEdge,g as gridPlacementGraphicSymbol,v as isLine,b as isUtilityNetworkWebMap,f as makeSnappingQuery,d as objectEqual,w as setupSnappingToggleHandles,u as sortCandidatesInPlace};
