/* COPYRIGHT Esri - https://js.arcgis.com/5.1.0/LICENSE.txt */
import{multiplyOpacityToUnitRGBA as e}from"../../core/colorUtils.js";import{handlesGroup as t}from"../../core/handleUtils.js";import{watch as r,initial as i,syncAndInitial as s}from"../../core/reactiveUtils.js";import{createScreenPoint as a}from"../../core/screenUtils.js";import{Manipulator3D as o}from"../3d/interactive/Manipulator3D.js";import{createManipulatorMaterial as n}from"../3d/interactive/manipulatorUtils.js";import{RenderObject as l}from"../3d/interactive/RenderObject.js";import{createSphereGeometry as u}from"../3d/webgl-engine/lib/GeometryUtil.js";import{getPointerType as c}from"./support/drawToolUtils.js";class d extends o{constructor(a){const o=n(e(a.view.effectiveTheme.accentColor,1)),c=[new l(u(o,1,32,32))];super({view:a.view,renderObjects:c,available:!1,radius:5,collisionPriority:1}),this.consumesClicks=!1,this.cursor="crosshair",this.grabCursor="grabbing",this._visualSymbol=Symbol("manipulator-visual"),this.renderer=a.renderer,this.managedHandle=a.managedHandle,this._handles=t([r(()=>a.view.effectiveTheme.accentColor,t=>{o.setParameters({color:e(t,1)})},i),r(()=>{const e=this.managedHandle;return[e?.role,e?.outputMapPosition,e?.grabbable,e?.following]},()=>this._syncFromHandle(),s)])}destroy(){this._handles.remove(),this.renderer?.removeVisual(this._visualSymbol),super.destroy()}get grabbing(){return super.grabbing}set grabbing(e){super.grabbing=e,this._updateVisual()}get following(){return!!this.managedHandle?.following}get hovering(){return super.hovering}set hovering(e){super.hovering=e,this._updateVisual()}get selected(){return super.selected}set selected(e){super.selected=e,this._updateVisual()}grabbableForEvent(e){if(!e)return this.grabbable;const t=a(e.x,e.y);return this.grabbable&&null!=this.intersectionDistance(t,c(e))}intersectionDistance(e,t){return this.following?0:super.intersectionDistance(e,t)}attach(e){super.attach(e),this._updateVisual()}detach(e){this.renderer?.removeVisual(this._visualSymbol),super.detach(e)}get _visualState(){return this.grabbing||this.following?"active":this.selected||this.hovering?"focused":"idle"}get _visualRole(){return"secondary"===this.managedHandle?.role?"controlPoint":"cursor"}_syncFromHandle(){const e=this.managedHandle,t=e?.outputMapPosition;this.available=!!t,this.grabbable=!!e?.grabbable,t&&(this.location=t),this._updateVisual()}_updateVisual(){this.renderer?.addOrUpdateVisual(this._visualSymbol,{role:this._visualRole,geometry:this.managedHandle?.outputMapPosition,state:this._visualState})}}export{d as DrawManipulator3D};
