/* COPYRIGHT Esri - https://js.arcgis.com/5.1.0/LICENSE.txt */
import{__decorate as e}from"tslib";import s from"../../core/Accessor.js";import t from"../../core/Collection.js";import{referenceSetter as i}from"../../core/collectionUtils.js";import{deprecateUnnecessaryViewModel as r}from"../../core/deprecate.js";import o from"../../core/Logger.js";import{isAbortError as l}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 j,generateFilterId as _}from"./support/filterUtils.js";import{createLoadLayersFunction as w}from"./support/layerUtils.js";let L=class extends s{constructor(e){super(e),this.view=null,this.state="disabled",this.level=new u({suppressDeprecationWarning:!0}),this.phase=new g({suppressDeprecationWarning:!0}),this.disciplines=new c,this._loadLayers=w(),e?.suppressDeprecationWarning||r(o.getLogger(this),"Building Explorer","arcgis-building-explorer",{version:"5.0"}),this.layers=new t}normalizeCtorArgs(e){const{suppressDeprecationWarning:s,...t}=e??{};return t}initialize(){this.addHandles([this.layers.on("change",()=>this._onLayersChange()),a(()=>({state:this.state,layers:this.layers,filter:this._filter}),({state:e,layers:s,filter:t})=>{"ready"===e&&f(s,t)},{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 s=e.filter(e=>e instanceof y);s.length!==e.length&&o.getLogger(this).error("Some layers are not BuildingSceneLayers but only BuildingSceneLayers can be passed to the widget."),this._set("layers",i(s,this._get("layers")))}get _filter(){const e=this.level.filterExpressions,s=this.phase.filterExpressions,t=[],i=v([e.solid,s.solid]);null!=i&&t.push(i);const r=j([e.xRay,s.xRay]);return null!=r&&t.push(r),0===t.length?null:new h({id:_(),name:"Building Explorer Filter",filterBlocks:t})}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(s){l(s)||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:t.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};
