/* COPYRIGHT Esri - https://js.arcgis.com/5.2/LICENSE.txt */
import{__decorate as t}from"tslib";import{equals as e}from"../core/arrayUtils.js";import{clone as s}from"../core/lang.js";import{property as r,subclass as i}from"../core/accessorSupport/decorators.js";import o from"./Extent.js";import n from"./Geometry.js";import p from"./Point.js";import a from"./SpatialReference.js";import{getMultipointExtent as l}from"./support/extentUtils.js";import{comparePoints as h}from"./support/geometryUtils.js";import{updateSupportFromPoint as u}from"./support/zmUtils.js";import{writer as c}from"../core/accessorSupport/decorators/writer.js";var m;function f(t){if(!t)return;let{points:e,hasM:s,hasZ:r,spatialReference:i}=t;switch(e??=[],e?.at(0)?.length){case 4:r??=!0,s??=!0;break;case 3:r??=!0!==s,s??=!r;break;default:r??=!1,s??=!1}return i??=a.WGS84,{...t,hasM:s,hasZ:r,points:e,spatialReference:i}}let y=m=class extends n{constructor(t){super(f(t)),this.points=[],this.type="multipoint"}get cache(){return this.commitProperty("points"),this.commitProperty("hasZ"),this.commitProperty("hasM"),this.commitProperty("spatialReference"),{}}get extent(){const t=l(this);return t?new o({...t,spatialReference:this.spatialReference}):null}writePoints(t,e){e.points=s(this.points)}clone(){const{points:t,spatialReference:e,hasM:r,hasZ:i}=this;return new m({points:s(t),spatialReference:e.clone(),hasM:r,hasZ:i})}equals(t){if(this===t)return!0;if(null==t)return!1;const s=this.spatialReference,r=t.spatialReference;return null!=s==(null!=r)&&(!(null!=s&&null!=r&&!s.equals(r))&&e(this.points,t.points,h))}addPoint(t){return u(this,t),Array.isArray(t)?this.points.push(t):this.points.push(t.toArray()),this.notifyChange("points"),this}getPoint(t){if(!this._validateInputs(t))return null;const e=this.points[t],s={x:e[0],y:e[1],spatialReference:this.spatialReference};let r=2;return this.hasZ&&(s.z=e[2],r=3),this.hasM&&(s.m=e[r]),new p(s)}removePoint(t){if(!this._validateInputs(t))return null;const e=new p(this.points.splice(t,1)[0],this.spatialReference);return this.notifyChange("points"),e}setPoint(t,e){return this._validateInputs(t)?(u(this,e),Array.isArray(e)||(e=e.toArray()),this.points[t]=e,this.notifyChange("points"),this):this}toJSON(t){return this.write({},t)}_validateInputs(t){return null!=t&&t>=0&&t<this.points.length}};t([r({readOnly:!0})],y.prototype,"cache",null),t([r({readOnly:!0})],y.prototype,"extent",null),t([r({type:[[Number]],json:{write:{isRequired:!0}}})],y.prototype,"points",void 0),t([c("points")],y.prototype,"writePoints",null),y=m=t([i("esri.geometry.Multipoint")],y),y.prototype.toJSON.isDefaultToJSON=!0;export{y as default};
