/*
All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
*/
import{__decorate as t}from"tslib";import{clone as e}from"../core/lang.js";import{property as s,subclass as r}from"../core/accessorSupport/decorators.js";import i from"./Extent.js";import a from"./Geometry.js";import n from"./Point.js";import h from"./SpatialReference.js";import{getPolylineExtent as o}from"./support/extentUtils.js";import{updateSupportFromPoint as p}from"./support/zmUtils.js";import{writer as l}from"../core/accessorSupport/decorators/writer.js";var u;function c(t){return!Array.isArray(t[0])}function f(t){return"number"==typeof t[0]?.[0]}function m(t){if(!t)return;let{paths:e,hasM:s,hasZ:r,spatialReference:i}=t;switch(e??=[],f(e)&&(e=[e]),e[0]?.[0]?.length){case 4:r??=!0,s??=!0;break;case 3:r??=!0!==s,s??=!r;break;default:r??=!1,s??=!1}return i??=h.WGS84,{...t,hasM:s,hasZ:r,paths:e,spatialReference:i}}let y=u=class extends a{constructor(t){super(m(t)),this.curvePaths=void 0,this.paths=[],this.type="polyline"}get cache(){return this.commitProperty("curvePaths"),this.commitProperty("hasM"),this.commitProperty("hasZ"),this.commitProperty("paths"),this.commitProperty("spatialReference"),{}}writeCurvePaths(t,s){s.curvePaths=e(t)}get extent(){const t=o(this),{spatialReference:e}=this;return t?new i({...t,spatialReference:e}):null}writePaths(t,s){s.paths=e(this.paths)}addPath(t){if(!t)return;const e=this.paths,s=e.length;if(c(t)){const r=[];for(let e=0,s=t.length;e<s;e++)r[e]=t[e].toArray();e[s]=r}else e[s]=t.slice();return this.notifyChange("paths"),this}clone(){const t=new u;return t.spatialReference=this.spatialReference,t.paths=e(this.paths),t.curvePaths=e(this.curvePaths),t.hasZ=this.hasZ,t.hasM=this.hasM,t}getPoint(t,e){if(!this._validateInputs(t,e))return null;const s=this.paths[t][e],r=this.hasZ,i=this.hasM;return r&&!i?new n(s[0],s[1],s[2],void 0,this.spatialReference):i&&!r?new n(s[0],s[1],void 0,s[2],this.spatialReference):r&&i?new n(s[0],s[1],s[2],s[3],this.spatialReference):new n(s[0],s[1],this.spatialReference)}insertPoint(t,e,s){return this._validateInputs(t,e,!0)?(p(this,s),Array.isArray(s)||(s=s.toArray()),this.paths[t].splice(e,0,s),this.notifyChange("paths"),this):this}removePath(t){if(!this._validateInputs(t,null))return null;const e=this.paths.splice(t,1)[0],s=this.spatialReference,r=e.map(t=>new n(t,s));return this.notifyChange("paths"),r}removePoint(t,e){if(!this._validateInputs(t,e))return null;const s=new n(this.paths[t].splice(e,1)[0],this.spatialReference);return this.notifyChange("paths"),s}setPoint(t,e,s){return this._validateInputs(t,e)?(p(this,s),Array.isArray(s)||(s=s.toArray()),this.paths[t][e]=s,this.notifyChange("paths"),this):this}_validateInputs(t,e,s=!1){if(null==t||t<0||t>=this.paths.length)return!1;if(null!=e){const r=this.paths[t];if(s&&(e<0||e>r.length))return!1;if(!s&&(e<0||e>=r.length))return!1}return!0}toJSON(t){return this.write({},t)}};t([s({readOnly:!0})],y.prototype,"cache",null),t([s({json:{write:!0,origins:{"portal-item":{write:!1},"web-map":{write:!1},"web-scene":{write:!1}}}})],y.prototype,"curvePaths",void 0),t([l("curvePaths")],y.prototype,"writeCurvePaths",null),t([s({readOnly:!0})],y.prototype,"extent",null),t([s({type:[[[Number]]],json:{write:{isRequired:!0}}})],y.prototype,"paths",void 0),t([l("paths")],y.prototype,"writePaths",null),y=u=t([r("esri.geometry.Polyline")],y),y.prototype.toJSON.isDefaultToJSON=!0;export{y as default};
