/*
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 e}from"tslib";import t from"../../core/Accessor.js";import s from"../../core/Collection.js";import{referenceSetter as i}from"../../core/collectionUtils.js";import{deprecateUnnecessaryViewModel as r}from"../../core/deprecate.js";import l from"../../core/Logger.js";import{isAbortError as o}from"../../core/promiseUtils.js";import{watch as a,whenOnce as n}from"../../core/reactiveUtils.js";import{property as p,subclass as d}from"../../core/accessorSupport/decorators.js";import y from"../../layers/BuildingSceneLayer.js";import h from"../../layers/support/BuildingFilter.js";import c from"./BuildingDisciplinesViewModel.js";import u from"./BuildingLevel.js";import g from"./BuildingPhase.js";import{showFullModel as m}from"./support/buildingLayerUtils.js";import{setFilterOnLayers as f,getFilterBlockSolid as v,getFilterBlockXRay as w,generateFilterId as j}from"./support/filterUtils.js";import{createLoadLayersFunction as _}from"./support/layerUtils.js";let L=class extends t{constructor(e){super(e),this.view=null,this.state="disabled",this.level=new u({isDefaultViewModel:!0}),this.phase=new g({isDefaultViewModel:!0}),this.disciplines=new c,this._loadLayers=_(),e?.isDefaultViewModel||r(l.getLogger(this),"Building Explorer","arcgis-building-explorer",{version:"5.0"}),this.layers=new s}normalizeCtorArgs(e){const{isDefaultViewModel:t,...s}=e??{};return s}initialize(){this.addHandles([this.layers.on("change",()=>this._onLayersChange()),a(()=>({state:this.state,layers:this.layers,filter:this._filter}),({state:e,layers:t,filter:s})=>{"ready"===e&&f(t,s)},{initial:!0})]),this._onLayersChange()}destroy(){this.level.destroyed||this.level.destroy(),this.phase.destroyed||this.phase.destroy(),this.disciplines.destroyed||this.disciplines.destroy()}get isSupported(){return"3d"===this.view?.type}get layers(){return this._get("layers")}set layers(e){const t=e.filter(e=>e instanceof y);t.length!==e.length&&l.getLogger(this).error("Some layers are not BuildingSceneLayers but only BuildingSceneLayers can be passed to the widget."),this._set("layers",i(t,this._get("layers")))}get _filter(){const e=this.level.filterExpressions,t=this.phase.filterExpressions,s=[],i=v([e.solid,t.solid]);null!=i&&s.push(i);const r=w([e.xRay,t.xRay]);return null!=r&&s.push(r),0===s.length?null:new h({id:j(),name:"Building Explorer Filter",filterBlocks:s})}async _onLayersChange(){const e=this.layers;if(this.level.layers=e,this.phase.layers=e,this.disciplines.layers=e,0!==e.length){this._set("state","loading");try{await this._loadLayers(e),await Promise.all([n(()=>"ready"===this.level.state),n(()=>"ready"===this.phase.state),n(()=>"ready"===this.disciplines.state)]),e.forEach(m),this._set("state","ready")}catch(t){o(t)||this._set("state","failed")}}else this._set("state","disabled")}};e([p({value:null})],L.prototype,"view",void 0),e([p()],L.prototype,"isSupported",null),e([p({type:s.ofType(y),nonNullable:!0})],L.prototype,"layers",null),e([p({readOnly:!0})],L.prototype,"state",void 0),e([p({readOnly:!0,type:u})],L.prototype,"level",void 0),e([p({readOnly:!0,type:g})],L.prototype,"phase",void 0),e([p({readOnly:!0,type:c})],L.prototype,"disciplines",void 0),e([p()],L.prototype,"_filter",null),L=e([d("esri.widgets.BuildingExplorer.BuildingExplorerViewModel")],L);const B=L;export{B as default};
