/* COPYRIGHT Esri - https://js.arcgis.com/5.1.2/LICENSE.txt */
import t from"../../../../Color.js";import{getContrast as e}from"../../../../core/colorUtils.js";import{watch as o,initial as r}from"../../../../core/reactiveUtils.js";import{identity as a,translate as i,scale as s,fromQuat as n,multiply as l}from"../../../../core/libs/gl-matrix-2/math/mat4.js";import{create as c}from"../../../../core/libs/gl-matrix-2/factories/mat4f64.js";import{rotationTo as m}from"../../../../core/libs/gl-matrix-2/math/quat.js";import{subtract as p,normalize as u,scale as f,add as d,set as g}from"../../../../core/libs/gl-matrix-2/math/vec3.js";import{create as h,fromValues as b}from"../../../../core/libs/gl-matrix-2/factories/vec3f64.js";import{sv3d as j,sm4d as M,sq4d as w}from"../../../../geometry/support/vectorStacks.js";import{shiftRestartOffsetDistance as v,shiftRestartTipRadius as y,shiftRestartTipLength as O,shiftRestartArrowOutlineWidth as U,shiftRestartArrowLength as x,shiftRestartTubeRadius as D,shiftRestartTubeFocusMultiplier as P,shiftRestartTipFocusMultiplier as R}from"../../analysis/Slice/sliceToolConfig.js";import{DidPointerMoveRecentlyFlag as C,IsShiftEdgeOnScreenFlag as G}from"../../analysis/Slice/sliceToolUtils.js";import{Manipulator3D as A}from"../Manipulator3D.js";import{RenderObject as B}from"../RenderObject.js";import{createPolylineGeometry as F,createConeGeometry as S,createPathExtrusionGeometry as T}from"../../webgl-engine/lib/GeometryUtil.js";import{ColorMaterial as H}from"../../webgl-engine/materials/ColorMaterial.js";import{RibbonLineMaterial as _}from"../../webgl-engine/materials/RibbonLineMaterial.js";class k extends A{constructor(a,i,s=4){const n=new _({width:1,renderOccluded:s,isDecoration:!0},a.state.isGlobal),l=new H({cullFace:2,renderOccluded:16,isDecoration:!0}),c=new H({cullFace:2,renderOccluded:16,isDecoration:!0}),m=new H({cullFace:2,renderOccluded:16,isDecoration:!0}),p=new H({writeDepth:!1,cullFace:1,renderOccluded:2,isDecoration:!0});super({view:a,...q({offsetMode:i,tubeMaterial:l,tipMaterial:c,capMaterial:m,outlineMaterial:p,calloutMaterial:n})}),this._themeHandle=o(()=>a.effectiveTheme.accentColor,o=>{const r=e(o),a=o.toUnitRGBA(),i=r.toUnitRGBA(),s=t.blendColors(r,o,.4).toUnitRGBA(),u=t.blendColors(r,o,.14).toUnitRGBA();n.setParameters({color:a}),l.setParameters({color:u}),c.setParameters({color:i}),m.setParameters({color:s}),p.setParameters({color:a})},r)}destroy(){this._themeHandle.remove(),super.destroy()}}function q({offsetMode:t,tubeMaterial:e,tipMaterial:o,capMaterial:r,outlineMaterial:a,calloutMaterial:i}){const s=0===t?v:0,n=[b(s,0,-x/2),b(s,0,x/2)],l=z(n),c=I({vertices:n,padding:0,materials:{tube:e,tip:o,cap:r}}),m=I({vertices:n,padding:U,materials:{tube:a,tip:a,cap:a}}),p=F(i,[[s,0,0],[s-v,0,0]]),u=F(i,[[s,0,0],[s-v,0,0]]);return{renderObjects:[...c.normal.map(t=>new B(t,1|C)),...m.normal.map(t=>new B(t,1|C)),new B(p,1|C|G),...c.focused.map(t=>new B(t,2|C)),...m.focused.map(t=>new B(t,2|C)),new B(u,2|C|G)],autoScaleRenderObjects:!1,collisionType:{type:"line",paths:[l]},collisionPriority:1,radius:y,state:C}}function I({vertices:t,padding:e,materials:o}){const r=r=>{const v=t.slice(),U=p(j.get(),v[0],v[1]);u(U,U);const x=p(j.get(),v[v.length-1],v[v.length-2]);if(u(x,x),e>0){const t=f(h(),x,-e);v[v.length-1]=d(t,t,v[v.length-1]);const o=f(h(),U,-e);v[0]=d(o,o,v[0])}const C=r?R:1,G=O*C,A=y*C,B=a(M.get());if(e>0){const t=G/4,o=g(j.get(),0,t,0),r=1+e/t;i(B,B,o),s(B,B,g(j.get(),r,r,r)),i(B,B,f(o,o,-1/r))}const F=a(c()),T=b(0,1,0),H=n(c(),m(w.get(),T,x));H[12]=v[v.length-1][0],H[13]=v[v.length-1][1],H[14]=v[v.length-1][2],l(H,H,B);const _=o.tube,k=L(D*(r?P:1)+e,v,_);k.transformation=F;const q=[k],I=o.tip,z=S(I,G,A,24,!1,!1,!0);z.transformation=H,q.push(z);const E=o.cap,J=S(E,G,A,24,!1,!0,!1);J.transformation=H,q.push(J);const K=n(c(),m(w.get(),T,U));return K[12]=v[0][0],K[13]=v[0][1],K[14]=v[0][2],l(K,K,B),q.push(z.instantiate({transformation:K})),q.push(J.instantiate({transformation:K})),q};return{normal:r(!1),focused:r(!0)}}function L(t,e,o){const r=[],a=12;for(let i=0;i<a;i++){const e=i/a*2*Math.PI;r.push([Math.cos(e)*t,Math.sin(e)*t])}return T(o,r,e,[],[],!1)}function z(t,e){const o=p(h(),t[t.length-1],t[t.length-2]);u(o,o),f(o,o,O),d(o,o,t[t.length-1]);{const e=p(h(),t[0],t[1]);return u(e,e),f(e,e,O),d(e,e,t[0]),[e,...t,o]}}export{k as ShiftManipulator};
