/*
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 t}from"tslib";import e from"../../core/Accessor.js";import o from"../../core/Logger.js";import{watch as i,syncAndInitial as s,when as r}from"../../core/reactiveUtils.js";import{property as l,subclass as n}from"../../core/accessorSupport/decorators.js";let u=class extends e{constructor(t){super(t),this.tool=null,this._loggedUnsupportedErrorOnce=!1,null!=t?.visible&&(this.visible=t.visible)}initialize(){this.addHandles(i(()=>({ready:null!=this.view&&this.view.ready,supported:this.supported}),({ready:t,supported:e})=>{!t||e||this._loggedUnsupportedErrorOnce||(this.logError(this.unsupportedErrorMessage),this._loggedUnsupportedErrorOnce=!0)},s))}destroy(){this.removeTool(),this.view=null}get active(){return null!=this.tool&&this.tool.active}get disabled(){return null==this.view||!this.view.ready||!this.supported}get supported(){return null==this.view||this.view.type===this.supportedViewType}get view(){return this._get("view")}set view(t){if(t===this.view)return;this.removeTool(),this._set("view",t);const e="tools";this.removeHandles(e),null!=t&&this.addHandles(t.tools.on("after-remove",t=>{t.item===this.tool&&this._set("tool",null)}),e)}set visible(t){this._set("visible",t),null!=this.tool&&(this.tool.visible=t)}createTool(t={interactive:!1}){if(this.removeTool(),null==this.view||!this.view.ready||!this.supported)return;const e=this.constructTool();e.created?(this._set("tool",e),this.view.tools.add(e)):t.interactive?(this._set("tool",e),this.view.addAndActivateTool(e),r(()=>e.created,()=>{e.active&&null!=this.view&&(this.view.activeTool=null)},{initial:!0,once:!0})):e.destroy()}removeTool(){const t=this.tool;if(null==t)return;const e=this.view?.tools;null!=e?e.remove(t):t.destroy(),this._set("tool",null)}logError(...t){o.getLogger(this).error(...t)}};t([l({constructOnly:!0})],u.prototype,"tool",void 0),t([l()],u.prototype,"active",null),t([l()],u.prototype,"disabled",null),t([l()],u.prototype,"supported",null),t([l({value:null})],u.prototype,"view",null),t([l({type:Boolean,value:!0})],u.prototype,"visible",null),u=t([n("esri.widgets.support.InteractiveToolViewModel")],u);const p=u;export{p as default};
