/* COPYRIGHT Esri - https://js.arcgis.com/5.0.18/LICENSE.txt */
import{__decorate as e}from"tslib";import t from"../../analysis/support/AnalysisOriginWebScene.js";import s from"../../core/Collection.js";import{castForReferenceSetter as i,referenceSetter as n}from"../../core/collectionUtils.js";import{subclass as o}from"../../core/accessorSupport/decorators.js";const r=["slice"];let a=class extends s{constructor(e){super(e),this.addHandles([this.on("after-add",e=>{this._setOrigin(e.item)}),this.on("before-remove",e=>{const{origin:t}=e.item;"web-scene"===t?.type&&this._setOrigin(e.item,null)})])}initialize(){for(const e of this.items)this._setOrigin(e)}_setOrigin(e,s=new t){e.origin=s}updateFrom(e){const s=e.analyses.filter(e=>c(e));this.removeAll(),s.length&&this.addMany(s.map(e=>(e.origin=new t,e.clone())))}applyTo(e){e.analyses.destroyMany(e.analyses.filter(({origin:e})=>"web-scene"===e?.type)),e.analyses.addMany(this.map(e=>e.clone()))}toJSON(e){return this.items.filter(c).map(t=>t.toJSON(e))}};function l(e){return{type:a,cast:i,clonable:e=>new a({items:e.items.map(e=>e.clone())}),set(t){this._set(e,n(t,this._get(e),a))},json:{read(t,s,i){i?.hooks?.onAfterLoad(()=>m(this[e],t,i))},write:{overridePolicy:e=>({enabled:e.length>0})}}}}function c(e){return r.includes(e.type)&&e.valid}async function m(e,t,s){if(!t)return;const i=await Promise.allSettled(t.map(e=>p(e,s)));for(const n of i)"fulfilled"===n.status&&e.add(n.value)}async function p(e,t){const s=new(await d[e.type]());return s.read(e,t),s}a=e([o("esri.webscene.support.analysisUtils.WebSceneAnalysesCollection")],a);const d={slice:async()=>{const{default:e}=await import("../../analysis/SliceAnalysis.js");return e}};export{a as WebSceneAnalysesCollection,l as webSceneAnalysisCollectionProperty,d as webSceneAnalysisRegistry};
