/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
import{isAbortError as t}from"../../../../core/promiseUtils.js";import{PlacementEngine as e}from"./Placement.js";import s from"./TileParser.js";class r{constructor(t,s,r,i){this.status=0,this.placementEngine=new e,this.tileKey=t,this.refKeys=s,this._workerTileHandler=r,this._styleRepository=i}release(){this.tileKey="",this.refKeys=null,this.status=0,this._workerTileHandler=null}async parse(e,s){const r=s?.signal;if(null!=r){const t=()=>{r.removeEventListener("abort",t),this.status=4};r.addEventListener("abort",t)}let i;const a={bucketsWithData:[],emptyBuckets:null};try{i=await this._parse(e,s)}catch(h){if(t(h))throw h;return{result:a,transferList:[]}}this.status=2;const n=a.bucketsWithData,l=[];for(const t of i)if(t.hasFeatures()){const e=t.serialize();n.push(e)}else l.push(t.layer.uid);const o=[...n];let u=null;return l.length>0&&(u=Uint32Array.from(l),o.push(u.buffer)),a.emptyBuckets=u,{result:a,transferList:o}}setObsolete(){this.status=4}getLayers(){return this._workerTileHandler.getLayers()}getWorkerTileHandler(){return this._workerTileHandler}async _parse(t,e){const r=t.sourceName2DataAndRefKey;if(0===Object.keys(r).length)return[];this.status=3;return new s(r,this,e.client,t.sourceDataMaxLOD,this._styleRepository,t.styleLayerUIDs).parse(e)}}export{r as default};
