/*
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","../request","../core/Error","../core/maybe","../core/object","../core/urlUtils","./utils","./support/NetworkServiceDescription"],(function(e,r,t,o,s,l,n,a,i){"use strict";function u(e,r,t,o){o[t]=[r.length,r.length+e.length],e.forEach((e=>{r.push(e.geometry)}))}function d(e,r){for(let t=0;t<r.length;t++){const o=e[r[t]];if(o&&o.length)for(const e of o)e.z=void 0}console.log("The remote Network Analysis service is powered by a network dataset which is not Z-aware.\nZ-coordinates of the input geometry are ignored.")}function p(e,r){for(let t=0;t<r.length;t++){const o=e[r[t]];if(o&&o.length)for(const e of o)if(s.isSome(e)&&e.hasZ)return!0}return!1}function c(e,r,t){return f.apply(this,arguments)}function f(){return(f=r._asyncToGenerator((function*(e,r,s){if(!e)throw new o("network-service:missing-url","Url to Network service is missing");const l={f:"json",token:r},n=a.asValidOptions(l,s),{data:u}=yield t(e,n);u.supportedTravelModes||(u.supportedTravelModes=[]);for(let t=0;t<u.supportedTravelModes.length;t++)u.supportedTravelModes[t].id||(u.supportedTravelModes[t].id=u.supportedTravelModes[t].itemId);const d=u.currentVersion>=10.4?T(e,r,s):v(e,s),{defaultTravelMode:p,supportedTravelModes:c}=yield d;return u.defaultTravelMode=p,u.supportedTravelModes=c,i.fromJSON(u)}))).apply(this,arguments)}function v(e,r){return h.apply(this,arguments)}function h(){return(h=r._asyncToGenerator((function*(e,r){var o,s;const i={f:"json"},u=a.asValidOptions(i,r),{data:d}=yield t(e.replace(/\/rest\/.*$/i,"/info"),u);if(!d||!d.owningSystemUrl)return{supportedTravelModes:[],defaultTravelMode:null};const{owningSystemUrl:p}=d,c=n.removeTrailingSlash(p)+"/sharing/rest/portals/self",{data:f}=yield t(c,u),v=l.getDeepValue("helperServices.routingUtilities.url",f);if(!v)return{supportedTravelModes:[],defaultTravelMode:null};const h=a.parseUrl(p),T={f:"json",serviceName:/\/solve$/i.test(h.path)?"Route":/\/solveclosestfacility$/i.test(h.path)?"ClosestFacility":"ServiceAreas"},M=a.asValidOptions(T,r),y=n.removeTrailingSlash(v)+"/GetTravelModes/execute",g=yield t(y,M),m=[];let w=null;if(null!=g&&null!=(o=g.data)&&null!=(s=o.results)&&s.length){const e=g.data.results;for(const r of e){var S;if("supportedTravelModes"===r.paramName){if(null!=(S=r.value)&&S.features)for(const{attributes:e}of r.value.features)if(e){const r=JSON.parse(e.TravelMode);m.push(r)}}else"defaultTravelMode"===r.paramName&&(w=r.value)}}return{supportedTravelModes:m,defaultTravelMode:w}}))).apply(this,arguments)}function T(e,r,t){return M.apply(this,arguments)}function M(){return(M=r._asyncToGenerator((function*(e,r,s){try{const o={f:"json",token:r},l=a.asValidOptions(o,s),i=n.removeTrailingSlash(e)+"/retrieveTravelModes",{data:{supportedTravelModes:u,defaultTravelMode:d}}=yield t(i,l);return{supportedTravelModes:u,defaultTravelMode:d}}catch(l){throw new o("network-service:retrieveTravelModes","Could not get to the NAServer's retrieveTravelModes.",{error:l})}}))).apply(this,arguments)}e.collectGeometries=u,e.dropZValuesOffInputGeometry=d,e.fetchServiceDescription=c,e.isInputGeometryZAware=p,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
