/* 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._defaultSymbolSortKey=0,this._nullResult=null,this._resultsMap=new Map,this._fields=[],this._fields=e,this._separator=t||""}static async fromMatcherSchema(e,s){const l=s.expression?[e.storage.createComputedField({expression:s.expression})]:[s.field?e.storage.createComputedField({field:s.field}):null,s.field2?e.storage.createComputedField({field:s.field2}):null,s.field3?e.storage.createComputedField({field:s.field3}):null],r=(await Promise.all(l)).filter(e=>!!e),i=new t(r,s.fieldDelimiter),a=await e.createMeshWriters(s.defaultSymbol);i.setDefault(a);const u=await e.createMeshWriters(s.backgroundFill);return i.setBackgroundFill(u),await Promise.all(s.map.map(async(t,s)=>{const l=await e.createMeshWriters(t.symbol);"<Null>"===t.value?i.setNullResult(l):i.add(t.value,l,s+1)})),i}setNullResult(e){this._nullResult=e}getSortKey(e,t){const s=this._getValueFromFields(e,t);if(null==s||""===s||"<Null>"===s)return 0;const l=this._resultsMap.get(s.toString());return l?l.sortKey:this._defaultSymbolSortKey}add(e,t,s){this._resultsMap.set(e.toString(),{meshWriters:t,sortKey:s}),this._defaultSymbolSortKey=Math.max(this._defaultSymbolSortKey,s+1)}size(){return super.size()+this._resultsMap.size}hasArcadeDependency(e){return this._fields.some(t=>t.hasArcadeDependency(e))||[...this._resultsMap.values()].some(t=>t.meshWriters.some(t=>t.hasArcadeDependency(e)))||this._nullResult?.some(t=>t.hasArcadeDependency(e))||!1}doMatch(e,t){const s=this._getValueFromFields(e,t);if(null!==this._nullResult&&(null==s||""===s||"<Null>"===s))return this._nullResult;if(null==s)return null;const l=s.toString();return this._resultsMap.get(l)?.meshWriters}_getValueFromFields(e,t){const s=[];for(const l of this._fields){const r=l.read(e,t);null==r||""===r?s.push("<Null>"):s.push(r)}return s.join(this._separator)}}export{t as MapMatcher};
