/*
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{EventedAccessor as e}from"../../core/Evented.js";import"../../core/has.js";import"../../core/Logger.js";import{createResolver as i}from"../../core/promiseUtils.js";import{property as a,subclass as o}from"../../core/accessorSupport/decorators.js";import{ManipulatorCollection as s}from"./ManipulatorCollection.js";let n=class extends e{constructor(t){super(t),this.manipulators=new s,this.automaticManipulatorSelection=!0,this.multiTouchEnabled=!0,this.hasGrabbedManipulators=!1,this.hasHoveredManipulators=!1,this.firstGrabbedManipulator=null,this.created=!1,this.removeIncompleteOnCancel=!0,this._editableFlags=new Map([[1,!0],[0,!0]]),this._creationFinishedResolver=i()}get active(){return null!=this.view&&this.view.activeTool===this}set visible(t){this._get("visible")!==t&&(this._set("visible",t),this._syncVisible())}get editable(){return this.getEditableFlag(0)}set editable(t){this.setEditableFlag(0,t)}get updating(){return!1}get cursor(){return null}get hasFocusedManipulators(){return this.hasGrabbedManipulators||this.hasHoveredManipulators}destroy(){this.manipulators.destroy(),this._set("view",null)}onAdd(){this._syncVisible()}activate(){null!=this.view&&(this.view.focus(),this.onActivate())}deactivate(){this.onDeactivate()}cancel(){this.emit("cancel")}handleInputEvent(t){this.onInputEvent(t)}handleInputEventAfter(t){this.onInputEventAfter(t)}setEditableFlag(t,e){this._editableFlags.set(t,e),this.manipulators.isToolEditable=this.internallyEditable,this._updateManipulatorAttachment(),0===t&&this.notifyChange("editable"),this.onEditableChange(),this.onManipulatorSelectionChanged()}getEditableFlag(t){return this._editableFlags.get(t)??!1}endDrag(){const t=this.view.inputManager.latestPointerInfo?.location;if(!t)return;let e=!1;this.manipulators.forEach(({manipulator:i})=>{i.dragging&&(e=!0,i.events.emit("drag",{action:"end",start:t,screenPoint:t}))}),e&&(this.view.toolViewManager.activeTool=null)}whenCreated(){return this._creationFinishedResolver.promise}onManipulatorSelectionChanged(){}onActivate(){}onDeactivate(){}onShow(){}onHide(){}onEditableChange(){}onInputEvent(t){}onInputEventAfter(t){}get internallyEditable(){return this.getEditableFlag(0)&&this.getEditableFlag(1)}finishToolCreation(){this.created||this._creationFinishedResolver.resolve(this),this._set("created",!0)}_syncVisible(){if(this.initialized)if(this.visible)this._show();else if(this._hide(),this.active)return void(this.view.activeTool=null)}_show(){this._updateManipulatorAttachment(),this.onShow()}_hide(){this._updateManipulatorAttachment(),this.onHide()}_updateManipulatorAttachment(){this.visible?this.manipulators.attach():this.manipulators.detach()}};t([a({constructOnly:!0})],n.prototype,"view",void 0),t([a({readOnly:!0})],n.prototype,"active",null),t([a({value:!0})],n.prototype,"visible",null),t([a({value:!0})],n.prototype,"editable",null),t([a({readOnly:!0})],n.prototype,"manipulators",void 0),t([a({readOnly:!0})],n.prototype,"updating",null),t([a()],n.prototype,"cursor",null),t([a({readOnly:!0})],n.prototype,"automaticManipulatorSelection",void 0),t([a({readOnly:!0})],n.prototype,"multiTouchEnabled",void 0),t([a()],n.prototype,"hasFocusedManipulators",null),t([a()],n.prototype,"hasGrabbedManipulators",void 0),t([a()],n.prototype,"hasHoveredManipulators",void 0),t([a()],n.prototype,"firstGrabbedManipulator",void 0),t([a({readOnly:!0})],n.prototype,"created",void 0),t([a({readOnly:!0})],n.prototype,"removeIncompleteOnCancel",void 0),n=t([o("esri.views.interactive.InteractiveToolBase")],n);export{n as InteractiveToolBase};
