/*
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","../../../geometry/projection","../../../geometry/geometryAdapters/json","../../../geometry/support/spatialReferenceUtils","../../../geometry/support/webMercatorUtils"],(function(e,t,n,s,r,i,o){"use strict";const a=[0,0];function u(e,t){if(!t)return null;if("x"in t){const n={x:0,y:0};return[n.x,n.y]=e(t.x,t.y,a),null!=t.z&&(n.z=t.z),null!=t.m&&(n.m=t.m),n}if("xmin"in t){const n={xmin:0,ymin:0,xmax:0,ymax:0};return[n.xmin,n.ymin]=e(t.xmin,t.ymin,a),[n.xmax,n.ymax]=e(t.xmax,t.ymax,a),t.hasZ&&(n.zmin=t.zmin,n.zmax=t.zmax,n.hasZ=!0),t.hasM&&(n.mmin=t.mmin,n.mmax=t.mmax,n.hasM=!0),n}return"rings"in t?{rings:c(t.rings,e),hasM:t.hasM,hasZ:t.hasZ}:"paths"in t?{paths:c(t.paths,e),hasM:t.hasM,hasZ:t.hasZ}:"points"in t?{points:l(t.points,e),hasM:t.hasM,hasZ:t.hasZ}:void 0}function c(e,t){const n=[];for(const s of e)n.push(l(s,t));return n}function l(e,t){const n=[];for(const s of e){const e=t(s[0],s[1],[0,0]);n.push(e),s.length>2&&e.push(s[2]),s.length>3&&e.push(s[3])}return n}function p(e,t){return m.apply(this,arguments)}function m(){return(m=t._asyncToGenerator((function*(e,t){if(!t)return;const r=Array.isArray(e)?e.map((e=>n.isSome(e.geometry)&&e.geometry.spatialReference)):[e];yield s.initializeProjection(r.map((e=>({source:e,dest:t}))))}))).apply(this,arguments)}const h=u.bind(null,o.lngLatToXY),f=u.bind(null,o.xyToLngLat);function y(e,t,n,a){if(!e)return e;if(n||(n=t,t=e.spatialReference),!i.isValid(t)||!i.isValid(n)||i.equals(t,n))return e;if(o.canProject(t,n)){const t=i.isWebMercator(n)?h(e):f(e);return t.spatialReference=n,t}return s.projectMany(r.jsonAdapter,[e],t,n,null,a)[0]}let x=function(){function e(){this._jobs=[],this._timer=null,this._process=this._process.bind(this)}var n=e.prototype;return n.push=function(){var e=t._asyncToGenerator((function*(e,t,n){if(!e||!e.length||!t||!n||i.equals(t,n))return e;const s={geometries:e,inSpatialReference:t,outSpatialReference:n,resolve:null};return this._jobs.push(s),new Promise((e=>{s.resolve=e,null===this._timer&&(this._timer=setTimeout(this._process,10))}))}));function n(t,n,s){return e.apply(this,arguments)}return n}(),n._process=function(){this._timer=null;const e=this._jobs.shift();if(!e)return;const{geometries:t,inSpatialReference:n,outSpatialReference:a,resolve:u}=e;o.canProject(n,a)?i.isWebMercator(a)?u(t.map(h)):u(t.map(f)):u(s.projectMany(r.jsonAdapter,t,n,a,null,null)),this._jobs.length>0&&(this._timer=setTimeout(this._process,10))},e}();const g=new x;function _(e,t,n){return g.push(e,t,n)}e.checkProjectionSupport=p,e.project=y,e.projectMany=_,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
