/* COPYRIGHT Esri - https://js.arcgis.com/5.0.18/LICENSE.txt */
import t from"../../../../../request.js";import{clone as r}from"../../../../../core/lang.js";import{getOrCreateMapValue as o}from"../../../../../core/MapUtils.js";import{isAborted as e,onAbort as s}from"../../../../../core/promiseUtils.js";import{urlToObject as i,addQueryParameters as n}from"../../../../../core/urlUtils.js";class l{constructor(t){this._tileUrl=t,this._promise=null,this._abortController=null,this._abortOptions=[]}getData(t){(null==this._promise||e(this._abortController?.signal))&&(this._promise=this._makeRequest(this._tileUrl));const o=this._abortOptions;return o.push(t),s(t,()=>{o.every(t=>e(t))&&this._abortController.abort()}),this._promise.then(t=>r(t))}async _makeRequest(r){this._abortController=new AbortController;const{data:o}=await t(r,{responseType:"array-buffer",signal:this._abortController.signal});return o}}const a=new Map;function c(t,r,o,e,s){const l=i(t),a=l.query;if(a)for(const[i,n]of Object.entries(a))switch(n){case"{x}":a[i]=e.toString();break;case"{y}":a[i]=o.toString();break;case"{z}":a[i]=r.toString()}const c=l.path;return p(n(c.replaceAll(/\{z\}/gi,r.toString()).replaceAll(/\{y\}/gi,o.toString()).replaceAll(/\{x\}/gi,e.toString()),{...l.query}),s)}function p(t,r){return o(a,t,()=>new l(t)).getData(r).finally(()=>a.delete(t))}export{c as request};
