/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["../../chunks/_rollupPluginBabelHelpers","../../chunks/tslib.es6","../../core/Accessor","../../core/Collection","../../core/collectionUtils","../../core/Handles","../../core/Logger","../../core/maybe","../../core/promiseUtils","../../core/reactiveUtils","../../core/accessorSupport/decorators/property","../../core/arrayUtils","../../core/has","../../core/accessorSupport/ensureType","../../core/accessorSupport/decorators/subclass","../../layers/BuildingSceneLayer","../../layers/support/BuildingFilter","./BuildingDisciplinesViewModel","./BuildingLevel","./BuildingPhase","./support/buildingLayerUtils","./support/filterUtils","./support/layerUtils"],(function(e,t,r,s,i,l,o,n,a,d,p,c,y,h,u,_,g,f,v,w,B,L,S){"use strict";const b=o.getLogger("esri.widgets.BuildingExplorer.BuildingExplorerViewModel");let x=function(t){function r(e){var r;return(r=t.call(this,e)||this).view=null,r.state="disabled",r.level=new v,r.phase=new w,r.disciplines=new f,r._handles=new l,r._loadLayers=S.createLoadLayersFunction(),r.layers=new s,r}e._inheritsLoose(r,t);var o=r.prototype;return o.initialize=function(){this._handles.add([this.layers.on("change",(()=>this._onLayersChange())),d.watch((()=>({state:this.state,layers:this.layers,filter:this._filter})),(({state:e,layers:t,filter:r})=>{"ready"===e&&L.setFilterOnLayers(t,r)}),{initial:!0})]),this._onLayersChange()},o.destroy=function(){this._handles.destroy(),this.level.destroyed||this.level.destroy(),this.phase.destroyed||this.phase.destroy(),this.disciplines.destroyed||this.disciplines.destroy()},o._onLayersChange=function(){var t=e._asyncToGenerator((function*(){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{yield this._loadLayers(e),yield Promise.all([d.whenOnce((()=>"ready"===this.level.state)),d.whenOnce((()=>"ready"===this.phase.state)),d.whenOnce((()=>"ready"===this.disciplines.state))]),e.forEach(B.showFullModel),this._set("state","ready")}catch(t){a.isAbortError(t)||this._set("state","failed")}}else this._set("state","disabled")}));function r(){return t.apply(this,arguments)}return r}(),e._createClass(r,[{key:"isSupported",get:function(){var e;return"3d"===(null==(e=this.view)?void 0:e.type)}},{key:"layers",set:function(e){const t=e.filter((e=>e instanceof _));t.length!==e.length&&b.error("Some layers are not BuildingSceneLayers but only BuildingSceneLayers can be passed to the widget."),this._set("layers",i.referenceSetter(t,this._get("layers")))}},{key:"_filter",get:function(){const e=this.level.filterExpressions,t=this.phase.filterExpressions,r=[],s=L.getFilterBlockSolid([e.solid,t.solid]);n.isSome(s)&&r.push(s);const i=L.getFilterBlockXRay([e.xRay,t.xRay]);return n.isSome(i)&&r.push(i),0===r.length?null:new g({id:L.generateFilterId(),name:"Building Explorer Filter",filterBlocks:r})}}]),r}(r);t.__decorate([p.property({value:null})],x.prototype,"view",void 0),t.__decorate([p.property()],x.prototype,"isSupported",null),t.__decorate([p.property({type:s,nonNullable:!0})],x.prototype,"layers",null),t.__decorate([p.property({readOnly:!0})],x.prototype,"state",void 0),t.__decorate([p.property({readOnly:!0,type:v})],x.prototype,"level",void 0),t.__decorate([p.property({readOnly:!0,type:w})],x.prototype,"phase",void 0),t.__decorate([p.property({readOnly:!0,type:f})],x.prototype,"disciplines",void 0),t.__decorate([p.property()],x.prototype,"_filter",null),x=t.__decorate([u.subclass("esri.widgets.BuildingExplorer.BuildingExplorerViewModel")],x);return x}));
