/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["../../../../chunks/_rollupPluginBabelHelpers","../../../../core/promiseUtils","./enums","./WorkerTile","./style/StyleRepository"],(function(e,t,s,r,n){"use strict";let o=function(){function o(){this._spriteInfo={},this._glyphInfo={}}var i=o.prototype;return i.reset=function(){return this._spriteInfo={},this._glyphInfo={},Promise.resolve()},i.getLayers=function(){var e;return null==(e=this._styleRepository)?void 0:e.layers},i.createTileAndParse=function(){var s=e._asyncToGenerator((function*(e,s){const{key:n}=e,o={};for(const t of Object.keys(e.sourceName2DataAndRefKey)){const s=e.sourceName2DataAndRefKey[t];o[t]=s.refKey}const i=new r(n,o,this,this._styleRepository);try{return yield i.parse(e,s)}catch(l){if(i.setObsolete(),i.release(),!t.isAbortError(l))throw l;return null}}));function n(e,t){return s.apply(this,arguments)}return n}(),i.updateStyle=function(e){if(!e||0===e.length||!this._styleRepository)return;const t=this._styleRepository;for(const r of e){const e=r.type,n=r.data;switch(e){case s.StyleUpdateType.PAINTER_CHANGED:t.setPaintProperties(n.layer,n.paint);break;case s.StyleUpdateType.LAYOUT_CHANGED:t.setLayoutProperties(n.layer,n.layout);break;case s.StyleUpdateType.LAYER_REMOVED:t.deleteStyleLayer(n.layer);break;case s.StyleUpdateType.LAYER_CHANGED:t.setStyleLayer(n.layer,n.index);break;case s.StyleUpdateType.SPRITES_CHANGED:this._spriteInfo={}}}},i.setStyle=function(e){this._styleRepository=new n(e),this._spriteInfo={},this._glyphInfo={}},i.fetchSprites=function(e,t,s){const r=[],n=this._spriteInfo;for(const o of e){void 0===n[o.name]&&r.push(o)}return 0===r.length?Promise.resolve():t.invoke("getSprites",r,{signal:s&&s.signal}).then((e=>{for(const t in e){const s=e[t];n[t]=s}}))},i.getSpriteItems=function(){return this._spriteInfo},i.fetchGlyphs=function(e,t,s,r,n){const o=[];let i=this._glyphInfo[t];return i?s.forEach((e=>{i[e]||o.push(e)})):(i=this._glyphInfo[t]=[],s.forEach((e=>o.push(e)))),0===o.length?Promise.resolve():r.invoke("getGlyphs",{tileID:e,font:t,codePoints:o},n).then((e=>{for(let t=0;t<e.length;t++)e[t]&&(i[t]=e[t])}))},i.getGlyphItems=function(e){return this._glyphInfo[e]},o}();return o}));
