/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["exports","../../chunks/_rollupPluginBabelHelpers","../../chunks/tslib.es6","../../core/Accessor","../../core/Handles","../../core/Logger","../../core/maybe","../../core/reactiveUtils","../../core/accessorSupport/decorators/property","../../core/arrayUtils","../../core/has","../../core/accessorSupport/ensureType","../../core/accessorSupport/decorators/subclass"],(function(e,t,o,i,r,s,l,n,a,c,d,p,u){"use strict";e.InteractiveToolViewModel=function(e){function o(t){var o;return(o=e.call(this,t)||this).tool=null,o._baseHandles=new r,o._loggedUnsupportedErrorOnce=!1,o.logger=s.getLogger(o.declaredClass),t&&null!=t.visible&&(o.visible=t.visible),o}t._inheritsLoose(o,e);var i=o.prototype;return i.initialize=function(){this._baseHandles.add(n.watch((()=>({ready:l.isSome(this.view)&&this.view.ready,supported:this.supported})),(({ready:e,supported:t})=>{!e||t||this._loggedUnsupportedErrorOnce||(this.logError(this.unsupportedErrorMessage),this._loggedUnsupportedErrorOnce=!0)}),n.syncAndInitial))},i.destroy=function(){this.removeTool(),this.view=null,this._baseHandles=l.destroyMaybe(this._baseHandles)},i.createTool=function(e={interactive:!1}){if(this.removeTool(),l.isNone(this.view)||!this.view.ready||!this.supported)return;const t=this.constructTool();t.created?(this._set("tool",t),this.view.tools.add(t)):e.interactive?(this._set("tool",t),this.view.addAndActivateTool(t),n.when((()=>t.created),(()=>{t.active&&l.isSome(this.view)&&(this.view.activeTool=null)}),{initial:!0,once:!0})):t.destroy()},i.removeTool=function(){const e=this.tool;if(l.isNone(e))return;const t=l.applySome(this.view,(e=>e.tools));l.isSome(t)?t.remove(e):e.destroy(),this._set("tool",null)},i.logError=function(...e){this.logger.error(...e)},t._createClass(o,[{key:"supported",get:function(){return l.isNone(this.view)||this.view.type===this.supportedViewType}},{key:"view",get:function(){return this._get("view")},set:function(e){if(e===this.view)return;this.removeTool(),this._set("view",e);const t="tools";this._baseHandles.remove(t),l.isNone(e)||this._baseHandles.add(e.tools.on("after-remove",(e=>{e.item===this.tool&&this._set("tool",null)})),t)}},{key:"visible",set:function(e){this._set("visible",e),l.isSome(this.tool)&&(this.tool.visible=e)}},{key:"active",get:function(){return l.isSome(this.tool)&&this.tool.active}},{key:"disabled",get:function(){return l.isNone(this.view)||!this.view.ready||!this.supported}}]),o}(i),o.__decorate([a.property({constructOnly:!0})],e.InteractiveToolViewModel.prototype,"tool",void 0),o.__decorate([a.property()],e.InteractiveToolViewModel.prototype,"supported",null),o.__decorate([a.property({value:null})],e.InteractiveToolViewModel.prototype,"view",null),o.__decorate([a.property({type:Boolean,value:!0})],e.InteractiveToolViewModel.prototype,"visible",null),o.__decorate([a.property()],e.InteractiveToolViewModel.prototype,"active",null),o.__decorate([a.property()],e.InteractiveToolViewModel.prototype,"disabled",null),e.InteractiveToolViewModel=o.__decorate([u.subclass("esri.widgets.support.InteractiveToolViewModel")],e.InteractiveToolViewModel),Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
