/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["../../chunks/_rollupPluginBabelHelpers","../../chunks/tslib.es6","../../geometry","../../core/maybe","../../core/accessorSupport/decorators/property","../../core/arrayUtils","../../core/has","../../core/accessorSupport/ensureType","../../core/accessorSupport/decorators/reader","../../core/accessorSupport/decorators/subclass","./DirectionsFeature","./FeatureSet","../../geometry/Extent","../../geometry/SpatialReference","../../geometry/Polyline","../../geometry/Point"],(function(e,t,r,o,s,n,a,p,i,u,l,c,y,m,d,f){"use strict";let h=function(t){function r(e){var r;return(r=t.call(this,e)||this).extent=null,r.features=null,r.geometryType="polyline",r.routeId=null,r.routeName=null,r.totalDriveTime=null,r.totalLength=null,r.totalTime=null,r}e._inheritsLoose(r,t);var s=r.prototype;return s.readFeatures=function(e,t){var r;if(!e)return[];const o=null!=(r=t.summary.envelope.spatialReference)?r:t.spatialReference,s=o&&m.fromJSON(o),n=e.map((e=>{var t,r;const o=this._decompressGeometry(e.compressedGeometry),n=new d({...o,spatialReference:s}),a=null!=(t=null==(r=e.events)?void 0:r.map((e=>{const{arriveTimeUTC:t,ETA:r,point:{x:o,y:n,z:a},strings:p}=e;return new l({geometry:new f({x:o,y:n,z:a,hasZ:void 0!==a,spatialReference:s}),attributes:{ETA:r,arriveTimeUTC:t},strings:p})})))?t:[];return new l({attributes:e.attributes,events:a,geometry:n,strings:e.strings})}));return n},s._decompressGeometry=function(e){let t=0,r=0,o=0,s=0;const n=[];let a,p,i,u,l,c,y,m,d=0,f=0,h=0;if(l=e.match(/((\+|\-)[^\+\-\|]+|\|)/g),l||(l=[]),0===parseInt(l[d],32)){d=2;const e=parseInt(l[d],32);d++,c=parseInt(l[d],32),d++,1&e&&(f=l.indexOf("|")+1,y=parseInt(l[f],32),f++),2&e&&(h=l.indexOf("|",f)+1,m=parseInt(l[h],32),h++)}else c=parseInt(l[d],32),d++;for(;d<l.length&&"|"!==l[d];){a=parseInt(l[d],32)+t,d++,t=a,p=parseInt(l[d],32)+r,d++,r=p;const e=[a/c,p/c];f&&(u=parseInt(l[f],32)+o,f++,o=u,e.push(u/y)),h&&(i=parseInt(l[h],32)+s,h++,s=i,e.push(i/m)),n.push(e)}return{paths:[n],hasZ:f>0,hasM:h>0}},s._mergePolylinesToSinglePath=function(e,t){if(0===e.length)return new d({spatialReference:t});const r=[];for(const a of e)for(const e of a.paths)r.push(...e);const o=[];r.forEach(((e,t)=>{0!==t&&e[0]===r[t-1][0]&&e[1]===r[t-1][1]||o.push(e)}));const{hasM:s,hasZ:n}=e[0];return new d({hasM:s,hasZ:n,paths:[o],spatialReference:t})},e._createClass(r,[{key:"mergedGeometry",get:function(){if(!this.features)return null;const e=this.features.map((({geometry:e})=>o.unwrap(e))),t=this.get("extent.spatialReference");return this._mergePolylinesToSinglePath(e,t)}},{key:"strings",get:function(){return this.features.map((({strings:e})=>e))}}]),r}(c);t.__decorate([s.property({type:y,json:{read:{source:"summary.envelope"}}})],h.prototype,"extent",void 0),t.__decorate([s.property()],h.prototype,"features",void 0),t.__decorate([i.reader("features")],h.prototype,"readFeatures",null),t.__decorate([s.property()],h.prototype,"geometryType",void 0),t.__decorate([s.property({readOnly:!0})],h.prototype,"mergedGeometry",null),t.__decorate([s.property()],h.prototype,"routeId",void 0),t.__decorate([s.property()],h.prototype,"routeName",void 0),t.__decorate([s.property({value:null,readOnly:!0})],h.prototype,"strings",null),t.__decorate([s.property({json:{read:{source:"summary.totalDriveTime"}}})],h.prototype,"totalDriveTime",void 0),t.__decorate([s.property({json:{read:{source:"summary.totalLength"}}})],h.prototype,"totalLength",void 0),t.__decorate([s.property({json:{read:{source:"summary.totalTime"}}})],h.prototype,"totalTime",void 0),h=t.__decorate([u.subclass("esri.rest.support.DirectionsFeatureSet")],h);return h}));
