/* COPYRIGHT Esri - https://js.arcgis.com/5.1.0/LICENSE.txt */
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 n,pausable as a}from"../../core/reactiveUtils.js";import{property as r,subclass as p}from"../../core/accessorSupport/decorators.js";let l=class extends t{constructor(e){super(e),this._viewpointHandle=null,this.group=null,e?.suppressDeprecationWarning||i(s.getLogger(this),"Expand","arcgis-expand",{version:"5.0"})}normalizeCtorArgs(e){const{suppressDeprecationWarning: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&&n(()=>e.ready,()=>{this.view===e&&this._watchViewpoint()},{once:!0,initial:!0}))}_viewpointHandleChange(e){this._viewpointHandle&&(e?n(()=>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=a(()=>"3d"===i.type?i.camera:i.viewpoint,()=>this._collapse());this.addHandles(s,e),this._viewpointHandle=s}_collapse(){this.expanded=!1}};e([r({value:!1})],l.prototype,"autoCollapse",null),e([r({value:!1})],l.prototype,"expanded",null),e([r()],l.prototype,"group",void 0),e([r({readOnly:!0})],l.prototype,"state",null),e([r({value:null})],l.prototype,"view",null),l=e([p("esri.widgets.Expand.ExpandViewModel")],l);const d=l;export{d as default};
