import{__decorate}from"tslib";import ProjectParameters from"@arcgis/core/tasks/support/ProjectParameters";import{validation}from"../../Validation.js";import{inline,isAbortable,schedulePromiseCancellation}from"./tools.js";import{MapProvider}from"./MapProvider.js";import{activate}from"../../Hooks.js";import{isArcGisApiVersionAtLeast,isArcGisApiVersion3x}from"./ArcGisApiVersion.js";import GeometryService from"@arcgis/core/tasks/GeometryService";async function canRunOnClient(){let e=!1;if((isArcGisApiVersionAtLeast("4.7")||isArcGisApiVersion3x&&isArcGisApiVersionAtLeast("3.24"))&&(e=!0),e){const r=await import("esri/geometry/projection");r.isSupported()||(e=!1)}return e}async function projectClient(e,r){const t=await import("esri/geometry/projection");var i=validation.array("geometry",e.geometry,validation.never),o=setGeographicTransformation(e.transformation),r=r.getOutSR(e.outSpatialReference);await t.load();let a;if(o)for(const s of t.getTransformations(i[0].spatialReference,r))if(s.steps[0].isInverse===e.reverse){if(s.steps[0].wkid&&o.wkid&&s.steps[0].wkid===o.wkid){a=s;break}if(s.steps[0].wkt&&o.wkt&&s.steps[0].wkt===o.wkt){a=s;break}}return t.project(i,r,a)}async function projectServer(e,r,t,i){const o=new ProjectParameters;o.geometries=validation.array("geometry",r.geometry,validation.never),o.transformation=setGeographicTransformation(r.transformation),o.transformForward=!r.reverse,isArcGisApiVersionAtLeast("4.4")?o.outSpatialReference=i.getOutSR(r.outSpatialReference):o.outSR=i.getOutSR(r.outSpatialReference);const a=new GeometryService(e);e=isAbortable(t.cancellationToken)?{signal:t.cancellationToken.signal}:void 0,e=a.project(o,e);return schedulePromiseCancellation(t,e),inline(e,function(e){return e})}function setGeographicTransformation(e){return"number"==typeof e?{wkid:e}:"string"==typeof e?{wkt:e}:"object"==typeof e?e:null}let ProjectServiceTask=class{async execute(e,r,t){var i=e.url;let o;return o=!i&&await canRunOnClient()?await projectClient(e,t):await projectServer(i||"https://utility.arcgisonline.com/ArcGIS/rest/services/Geometry/GeometryServer",e,r,t),{geometry:o[0],results:o}}};ProjectServiceTask.action="gcx:wf:arcgis::ProjectServiceTask",ProjectServiceTask.suite="gcx:wf:builtin",ProjectServiceTask=__decorate([activate(MapProvider)],ProjectServiceTask);export{ProjectServiceTask};