/* COPYRIGHT Esri - https://js.arcgis.com/5.0.18/LICENSE.txt */
import{DictionaryScriptEvaluator as t}from"../../../../../renderers/support/DictionaryScriptEvaluator.js";import{FeatureMatcher as r}from"./Matcher.js";class e extends r{static async fromDictionaryRenderer(r,o){const n=await t.from(o.dictionaryInfo,o.userConfig,o.fieldMap);return new e(r,n)}constructor(t,r){super(),this._context=t,this._evaluator=r,this._controlStringToPromise=new Map,this._controlStringToGroup=new Map}async fetchResources(t,r){const e=r.getCursor(),o=new Set;for(;e.next();){const t=this._evaluateControlString(e);t&&o.add(t)}const n=Array.from(o.values()).map(r=>this._ensureGroup(t,r));await Promise.all(n)}match(t,r){const e=this._evaluateControlString(t);return e?this._controlStringToGroup.get(e):null}_evaluateControlString(t){const r=t.readLegacyFeatureWorldSpace();return this._evaluator.evaluate(r,0,t.fields,null)}_ensureGroup(t,r){let e=this._controlStringToPromise.get(r);return null==e&&(e=this._fetchGroup(t,r),this._controlStringToPromise.set(r,e)),e}async _fetchGroup(t,r){const e=await t.fetchDictionaryResourceImmediate({type:"dictionary-request",controlString:r});if(!e)return;const o=await this._context.createMeshWriters(e.meshes);this._controlStringToGroup.set(r,o)}}export{e as DictionaryMatcher};
