/* COPYRIGHT Esri - https://js.arcgis.com/5.2/LICENSE.txt */
import{getMetersPerUnitForSR as e}from"../../../core/units.js";import n from"../../../geometry/Extent.js";import{getWebMercatorScalingFactor as t}from"../../../layers/orientedImagery/transformations/utils.js";import{clockwiseDirections as r}from"../constants.js";function o(r,o){const{x:i,y:u,spatialReference:s}=r,a=o*t(u,s)/e(s);return new n({xmin:i-a,xmax:i+a,ymin:u-a,ymax:u+a,spatialReference:r.spatialReference})}function i(e){return!e||null===e.previous||null===e.next}function u(e,n,t=1){if(null==e[n])return!0;const o=e=>e?r.reduce((n,t)=>e[t]?n+1:n,0):0,i=new Set,u=[{node:e,depth:0}];for(;u.length;){const{node:e,depth:n}=u.shift();if(e&&!i.has(e)){if(i.add(e),o(e)<2)return!0;if(n<t)for(const t of r){const r=e[t];r&&!i.has(r)&&u.push({node:r,depth:n+1})}}}return!1}function s(e,n){if(!e&&!n)return 0;const t=Number(e),r=Number(n);if(!isNaN(t)&&!isNaN(r))return t-r;const o=String(e),i=String(n);return o<i?-1:o>i?1:0}function a(e,n){if(!e)return"1=1";switch(n){case"next":return f(e,"next");case"previous":return f(e,"previous");default:return"1=1"}}function f(e,n){return e.map((t,r)=>{const o=e.slice(0,r).map(e=>e?.value?`(${e.fieldName} = ${e.value})`:null).filter(Boolean).join(" AND "),i="asc"===t.sortOrder?"next"===n?">":"<":"next"===n?"<":">",u=[o,t?.value?`(${t.fieldName} ${i} ${t.value})`:null].filter(Boolean);return u.length>1?`(${u.join(" AND ")})`:u.join(" AND ")}).filter(Boolean).join(" OR ")}export{a as constructWhereClauseForSequenceFields,o as createExtentAroundPoint,u as shouldQueryAndNavigate,i as shouldQueryAndNavigateSequentially,s as sortStringOrNumber};
