import Point from"@arcgis/core/geometry/Point";import{GenericActivityError}from"../../Errors.js";import{validation}from"../../Validation.js";class GetCurrentPosition{constructor(){this.geolocation=navigator.geolocation}execute(u){return new Promise((e,r)=>{if(!this.geolocation)return r(new GenericActivityError("WF0016","Geolocation is not supported."));r={enableHighAccuracy:validation.boolean("enableHighAccuracy",u.enableHighAccuracy,void 0),maximumAge:validation.number("maximumAge",u.maximumAge,void 0),timeout:validation.number("timeout",u.timeout,2e4)};const c=o=>e({position:new Point({x:o.coords.longitude,y:o.coords.latitude,spatialReference:{wkid:4326}}),accuracy:o.coords.accuracy,altitude:o.coords.altitude,altitudeAccuracy:o.coords.altitudeAccuracy,heading:o.coords.heading,latitude:o.coords.latitude,longitude:o.coords.longitude,speed:o.coords.speed,timestamp:o.timestamp}),a=o=>e({errorCode:o.code,errorMessage:o.message});if(u.useMultipleReadings){let o,e,t;const n=validation.number("accuracyThreshold",u.accuracyThreshold,10);let i=!1;const s=()=>{i||(i=!0,this.geolocation.clearWatch(o),clearTimeout(e),t?c(t):a({code:3,message:"A geolocated position could not be obtained before the timeout."}))};e=setTimeout(()=>{s()},r.timeout),o=this.geolocation.watchPosition(o=>{(!t||o.coords.accuracy<=t.coords.accuracy)&&(t=o),t.coords.accuracy<=n&&s()},a,r)}else this.geolocation.getCurrentPosition(c,a,r)})}}GetCurrentPosition.action="gcx:wf:arcgis::GetCurrentPosition",GetCurrentPosition.suite="gcx:wf:builtin";export{GetCurrentPosition};