/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["exports","../../../../../chunks/_rollupPluginBabelHelpers","../../../../../core/maybe","./config"],(function(o,e,t,i){"use strict";function s(o,e){if(o.priority-e.priority)return o.priority-e.priority;const t=o.tile.key,i=e.tile.key;return t.world-i.world?t.world-i.world:t.level-i.level?t.level-i.level:t.row-i.row?t.row-i.row:t.col-i.col?t.col-i.col:o.xTile-e.xTile?o.xTile-e.xTile:o.yTile-e.yTile}let n=function(){function o(o,e,t,i,s,n){this._visibleTiles=o,this._symbolRepository=e,this._createCollisionJob=t,this._assignTileSymbolsOpacity=i,this._symbolLayerSorter=s,this._isLayerVisible=n,this._selectionJob=null,this._selectionJobCompleted=!1,this._collisionJob=null,this._collisionJobCompleted=!1,this._opacityJob=null,this._opacityJobCompleted=!1,this._running=!0}var i=o.prototype;return i.setScreenSize=function(o,e){this._screenWidth===o&&this._screenHeight===e||this.restart(),this._screenWidth=o,this._screenHeight=e},i.restart=function(){this._selectionJob=null,this._selectionJobCompleted=!1,this._collisionJob=null,this._collisionJobCompleted=!1,this._opacityJob=null,this._opacityJobCompleted=!1,this._running=!0},i.continue=function(o){if(this._selectionJob||(this._selectionJob=this._createSelectionJob()),!this._selectionJobCompleted){const e=performance.now();if(!this._selectionJob.work(o))return!1;if(this._selectionJobCompleted=!0,0===(o=Math.max(0,o-(performance.now()-e))))return!1}if(this._collisionJob||(this._collisionJob=this._createCollisionJob(this._selectionJob.sortedSymbols,this._screenWidth,this._screenHeight)),!this._collisionJobCompleted){const e=performance.now();if(!this._collisionJob.work(o))return!1;if(this._collisionJobCompleted=!0,0===(o=Math.max(0,o-(performance.now()-e))))return!1}if(this._opacityJob||(this._opacityJob=this._createOpacityJob()),!this._opacityJobCompleted){const e=performance.now();if(!this._opacityJob.work(o))return!1;if(this._opacityJobCompleted=!0,0===(o=Math.max(0,o-(performance.now()-e))))return!1}return this._running=!1,!0},i._createSelectionJob=function(){const o=this._symbolRepository.uniqueSymbols;for(let s=0;s<o.length;s++){const e=o[s];for(let o=0;o<e.uniqueSymbols.length;o++){const t=e.uniqueSymbols[o];for(const o of t.tileSymbols)o.selectedForRendering=!1}}const e=[];let t=0,i=0;const n=this._isLayerVisible;function r(r){let l;const c=performance.now();for(;i<o.length;i++,t=0){const s=o[i],a=s.styleLayerUID;if(!n(a)){e[i]||(e[i]={styleLayerUID:a,symbols:[]});continue}e[i]=e[i]||{styleLayerUID:a,symbols:[]};const h=e[i];for(;t<s.uniqueSymbols.length;t++){if(l=s.uniqueSymbols[t],t%100==99&&performance.now()-c>r)return!1;let o=null,e=!1,i=!1;for(const t of l.tileSymbols)if(!i||!e){const s=t.tile;(!o||s.isCoverage||s.neededForCoverage&&!e)&&(o=t,(s.neededForCoverage||s.isCoverage)&&(i=!0),s.isCoverage&&(e=!0))}if(o.selectedForRendering=!0,i){h.symbols.push(o),l.show=!0;for(const o of l.parts)o.show=!0}else l.show=!1}}for(const o of e)o.symbols.sort(s);return!0}const l=this._symbolLayerSorter;return{work:r,get sortedSymbols(){return e.sort(l)}}},i._createOpacityJob=function(){const o=this._assignTileSymbolsOpacity,e=this._visibleTiles;let i=0;function s(e,t){const i=e.symbols;for(const[o,s]of i)r(s,t);o(e,t);for(const o of e.childrenTiles)s(o,t)}return{work(o){const n=performance.now();for(;i<e.length;i++){if(performance.now()-n>o)return!1;const r=e[i];if(t.isSome(r.parentTile))continue;s(r,performance.now())}return!0}}},e._createClass(o,[{key:"running",get:function(){return this._running}}]),o}();function r(o,e){for(const t of o){const o=t.unique;for(const t of o.parts){const s=t.targetOpacity>.5?1:-1;t.startOpacity+=s*((e-t.startTime)/i.FADE_DURATION),t.startOpacity=Math.min(Math.max(t.startOpacity,0),1),t.startTime=e,t.targetOpacity=o.show&&t.show?1:0}}}o.SymbolDeclutterer=n,Object.defineProperties(o,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
