/*
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{deprecateUnnecessaryViewModel as i}from"../../core/deprecate.js";import s from"../../core/Logger.js";import{on as o,when as a,pausable as n}from"../../core/reactiveUtils.js";import{property as l,subclass as r}from"../../core/accessorSupport/decorators.js";let p=class extends t{constructor(e){super(e),this._viewpointHandle=null,this.group=null,e?.isDefaultViewModel||i(s.getLogger(this),"Expand","arcgis-expand",{version:"5.0"})}normalizeCtorArgs(e){const{isDefaultViewModel:t,...i}=e??{};return i}initialize(){this.addHandles(o(()=>this.view?.ui,"expand",e=>{const{target:t}=e;t&&t!==this&&t.expanded&&t.group&&t.group===this.group&&this._collapse()}))}destroy(){this._viewpointHandle=null,this.view=null}set autoCollapse(e){this._set("autoCollapse",e),this._watchViewpoint()}set expanded(e){const t=!!e;this._set("expanded",t);const i=this.view?.ui;i&&i.emit("expand",{target:this}),this._viewpointHandleChange(t)}get state(){return this.view?.ready?"ready":"disabled"}set view(e){this._get("view")!==e&&(this._set("view",e),e&&a(()=>e.ready,()=>{this.view===e&&this._watchViewpoint()},{once:!0,initial:!0}))}_viewpointHandleChange(e){this._viewpointHandle&&(e?a(()=>this.view?.stationary,()=>this._viewpointHandle?.resume(),{once:!0,initial:!0}):this._viewpointHandle.pause())}_watchViewpoint(){const e="viewpoint";this.removeHandles(e),this._viewpointHandle=null;const{autoCollapse:t,view:i}=this;if(!i||!t)return;const s=n(()=>"3d"===i.type?i.camera:i.viewpoint,()=>this._collapse());this.addHandles(s,e),this._viewpointHandle=s}_collapse(){this.expanded=!1}};e([l({value:!1})],p.prototype,"autoCollapse",null),e([l({value:!1})],p.prototype,"expanded",null),e([l()],p.prototype,"group",void 0),e([l({readOnly:!0})],p.prototype,"state",null),e([l({value:null})],p.prototype,"view",null),p=e([r("esri.widgets.Expand.ExpandViewModel")],p);const d=p;export{d as default};
