/* COPYRIGHT Esri - https://js.arcgis.com/5.1.2/LICENSE.txt */
import{floatGreaterThan as e,floatLessThan as n,floatEqualAbsolute as t,floatGreaterThanOrEqual as r}from"../../core/mathUtils.js";import{sqlOr as o}from"../../core/sql.js";function i(e,n){return{...n,filterMode:e.mode}}function u(e,n){return l(e,n).next().value??null}function c(t,r,i){const u=f(t);if(u&&(e(r,u[0])||n(i,u[1])))return"";const c=Array.from(l(t,r,i)),m=a(c,r,i)?"1=1":c.map(e=>e.where||"1=1").reduce((e,n)=>o(e,n),"");return m&&"1=1"!==m?m:""}function f(e){if("manual"===s(e))return null;const n=[Number.NEGATIVE_INFINITY,Number.POSITIVE_INFINITY];for(const{minScale:t,maxScale:r}of e.filters)n[0]=Math.max(n[0],I(t)),n[1]=Math.min(n[1],d(r));return n}function*l(e,n,t){if("manual"===s(e)){const n=e.filters.find(n=>n.id===e.activeFilterId);n&&(yield n)}else{"object"==typeof n&&(n=n.scale);for(const r of e.filters)m(r.minScale,r.maxScale,n,t)&&(yield r)}}function a(t,r,o){if(0===t.length)return!0;const i=I(t.at(0)?.minScale),u=d(t.at(-1)?.maxScale);if(n(i,r)||e(u,o))return!0;for(let e=0;e<t.length-1;e++){const r=t[e],o=t[e+1];if(n(I(o.minScale),d(r.maxScale)))return!0}return!1}function m(e,n,o,i){return e=I(e),o=I(o),n=d(n),!(!t(o,e)&&(i??o)>e)&&(!r(n,o)&&(void 0===i||!t(i,e)))}function s(e){return"mode"in e?e.mode:e.filterMode}function I(e){return e||Number.POSITIVE_INFINITY}function d(e){return e||0}export{i as createDisplayFilterJSONContext,c as getClauseForScaleRange,u as getEffectiveDisplayFilter};
