/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
import{FeatureMatcher as e}from"./Matcher.js";class t extends e{constructor(e,t){super(),this._intervals=[],this._isMaxInclusive=t,this._field=e}static async fromIntervalSchema(e,s){const r=await e.storage.createComputedField(s),a=new t(r,s.isMaxInclusive);await Promise.all(s.intervals.map(async t=>{const s=await e.createMeshWriters(t.meshes);a.add(t,s)}));const i=await e.createMeshWriters(s.defaultSymbol);a.setDefault(i);const n=await e.createMeshWriters(s.backgroundFill);return a.setBackgroundFill(n),a}add(e,t){this._intervals.push({interval:e,result:t}),this._intervals.sort((e,t)=>e.interval.min-t.interval.min)}size(){return super.size()+this._intervals.length}hasArcadeDependency(e){return this._field?.hasArcadeDependency(e)||this._intervals.some(t=>t.result.some(t=>t.hasArcadeDependency(e)))}doMatch(e,t){const s=this._field?.read(e,t);if(null==s||isNaN(s)||s===1/0||s===-1/0)return null;for(let r=0;r<this._intervals.length;r++){const{interval:e,result:t}=this._intervals[r],a=s>=e.min,i=this._isMaxInclusive?s<=e.max:s<e.max;if(a&&i)return t}return null}}export{t as IntervalMatcher};
