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