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