/* COPYRIGHT Esri - https://js.arcgis.com/5.1.2/LICENSE.txt */
import{__decorate as t}from"tslib";import{EventedAccessor as e}from"../../core/Evented.js";import"../../core/has.js";import"../../core/Logger.js";import{property as i,subclass as a}from"../../core/accessorSupport/decorators.js";import{ManipulatorCollection as o}from"./ManipulatorCollection.js";let s=class extends e{constructor(t){super(t),this.manipulators=new o,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=Promise.withResolvers()}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([i({constructOnly:!0})],s.prototype,"view",void 0),t([i({readOnly:!0})],s.prototype,"active",null),t([i({value:!0})],s.prototype,"visible",null),t([i({value:!0})],s.prototype,"editable",null),t([i({readOnly:!0})],s.prototype,"manipulators",void 0),t([i({readOnly:!0})],s.prototype,"updating",null),t([i()],s.prototype,"cursor",null),t([i({readOnly:!0})],s.prototype,"automaticManipulatorSelection",void 0),t([i({readOnly:!0})],s.prototype,"multiTouchEnabled",void 0),t([i()],s.prototype,"hasFocusedManipulators",null),t([i()],s.prototype,"hasGrabbedManipulators",void 0),t([i()],s.prototype,"hasHoveredManipulators",void 0),t([i()],s.prototype,"firstGrabbedManipulator",void 0),t([i({readOnly:!0})],s.prototype,"created",void 0),t([i({readOnly:!0})],s.prototype,"removeIncompleteOnCancel",void 0),s=t([a("esri.views.interactive.InteractiveToolBase")],s);export{s as InteractiveToolBase};
