/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.25/esri/copyright.txt for details. */ import r from"../request.js";import{normalizeCentralMeridian as e}from"../geometry/support/normalizeUtils.js";import{collectGeometries as t,isInputGeometryZAware as o,fetchServiceDescription as i,dropZValuesOffInputGeometry as s}from"./networkService.js";import{parseUrl as a}from"./utils.js";import{serviceAreaParametersToQueryParameters as n}from"./route/utils.js";import f from"./support/FeatureSet.js";import p from"./support/ServiceAreaSolveResult.js";function u(r){return r instanceof f}async function l(f,l,c){const m=[],y=[],B={},j={},g=a(f),{path:S}=g;u(l.facilities)&&t(l.facilities.features,y,"facilities.features",B),u(l.pointBarriers)&&t(l.pointBarriers.features,y,"pointBarriers.features",B),u(l.polylineBarriers)&&t(l.polylineBarriers.features,y,"polylineBarriers.features",B),u(l.polygonBarriers)&&t(l.polygonBarriers.features,y,"polygonBarriers.features",B);const h=await e(y);for(const r in B){const e=B[r];m.push(r),j[r]=h.slice(e[0],e[1])}if(o(j,m)){let r=null;try{r=await i(S,l.apiKey,c)}catch{}r&&!r.hasZ&&s(j,m)}for(const r in j)j[r].forEach(((e,t)=>{l.get(r)[t].geometry=e}));const v={...c,query:{...g.query,...n(l),f:"json"}},{data:w}=await r(`${S}/solveServiceArea`,v);return p.fromJSON(w)}export{l as solve};