/* COPYRIGHT Esri - https://js.arcgis.com/5.1.2/LICENSE.txt */
import{__decorate as e}from"tslib";import t from"./Analysis.js";import n from"./DimensionSimpleStyle.js";import i from"./LengthDimension.js";import{equals as s}from"../core/arrayUtils.js";import o from"../core/Collection.js";import{referenceSetter as l,castForReferenceSetter as r}from"../core/collectionUtils.js";import{watch as p,syncAndInitial as u}from"../core/reactiveUtils.js";import{property as m,subclass as a}from"../core/accessorSupport/decorators.js";import d from"../geometry/Extent.js";import{projectOrLoadMany as c}from"../geometry/projectionUtils.js";const y=o.ofType(i);let f=class extends t{constructor(e){super(e),this.type="dimension",this.style=new n,this.extent=null}initialize(){this.addHandles(p(()=>this._computeExtent(),e=>{null==e?.pending&&this._set("extent",null!=e?e.extent:null)},u))}get dimensions(){return this._get("dimensions")||new y}set dimensions(e){this._set("dimensions",l(e,this.dimensions,y))}get spatialReference(){for(const e of this.dimensions){if(null!=e.startPoint)return e.startPoint.spatialReference;if(null!=e.endPoint)return e.endPoint.spatialReference}return null}get valid(){return this.dimensions.every(e=>e.valid)}async waitComputeExtent(){const e=this._computeExtent();return null!=e?e.pending:Promise.resolve()}_computeExtent(){const e=this.spatialReference;if(null==e)return{pending:null,extent:null};const t=[];for(const s of this.dimensions)null!=s.startPoint&&t.push(s.startPoint),null!=s.endPoint&&t.push(s.endPoint);const n=c(t,e);if(null!=n.pending)return{pending:n.pending,extent:null};let i=null;return null!=n.geometries&&(i=n.geometries.reduce((e,t)=>null==e?null!=t?d.fromPoint(t):null:null!=t?e.union(d.fromPoint(t)):e,null)),{pending:null,extent:i}}clear(){this.dimensions.removeAll()}equals(e){return this===e||super.equals(e)&&this.style.equals(e.style)&&s(this.dimensions.toArray(),e.dimensions.toArray(),(e,t)=>e.equals(t))}};e([m({type:["dimension"]})],f.prototype,"type",void 0),e([m({cast:r,type:y,nonNullable:!0})],f.prototype,"dimensions",null),e([m({readOnly:!0})],f.prototype,"spatialReference",null),e([m({types:{key:"type",base:null,typeMap:{simple:n}},nonNullable:!0})],f.prototype,"style",void 0),e([m({value:null,readOnly:!0})],f.prototype,"extent",void 0),e([m({readOnly:!0})],f.prototype,"valid",null),f=e([a("esri.analysis.DimensionAnalysis")],f);export{f as default};
