/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["exports","../../../../core/handleUtils","../../../../core/mathUtils","../../../../core/maybe","../../../../core/reactiveUtils","../../../../chunks/vec3","../../../../chunks/vec3f64","../../../../geometry/projection","../../../../geometry/support/aaBoundingBox","../../../../geometry/support/aaBoundingRect","../../../../support/elevationInfoUtils","./GrabbingState","./ManipulatorState","./settings","../visualElements/ExtendedLineVisualElement","../visualElements/LaserlineVisualElement","../visualElements/PointVisualElement","../../layers/graphics/elevationAlignmentUtils","../../layers/graphics/ElevationContext","../../layers/graphics/GraphicState","../../webgl-engine/lib/Material"],(function(e,t,n,a,i,s,l,o,r,c,p,u,d,h,g,v,m,f,y,E,w){"use strict";function b(e){const{view:n,graphic:a}=e,i=new E.GraphicState({graphic:a}),s=[],l=V(e,i,s);return S(e,i,s,l),s.push(n.trackGraphicState(i)),{visualElement:l,remove(){t.handlesGroup(s).remove()}}}function S(e,l,c,m){const{view:E,graphic:b}=e,S=new g.ExtendedLineVisualElement({view:E,extensionType:h.settings.visualElements.zVerticalLine.extensionType,innerWidth:1,attached:!1,writeDepthEnabled:!1,renderOccluded:w.RenderOccludedFlag.OccludeAndTransparent});h.settings.visualElements.zVerticalLine.apply(S);const V=new v.LaserlineVisualElement({view:E,intersectsLineInfinite:!0,attached:!1});h.settings.visualElements.pointGraphics.shadowStyle.apply(V);const M=n.deg2rad(h.settings.visualElements.heightPlaneAngleCutoff),P=new v.LaserlineVisualElement({view:E,attached:!1,angleCutoff:M});h.settings.visualElements.heightPlane.apply(P);const x=p.getGraphicEffectiveElevationInfo(e.graphic),H=y.ElevationContext.fromElevationInfo(x),T="on-the-ground"===x.mode||!x.offset&&"absolute-height"!==x.mode,C=new d.ManipulatorState;let R=1,I=1;const U=()=>{C.update(e);const t=G(b),n=T&&(l.isDraped||a.isNone(t)||!t.hasZ);let i=!0;if(!n&&a.isSome(t)){const e=f.evaluateElevationAlignmentAtPoint(t,E.elevationProvider,H,E.renderCoordsHelper);s.set(L,t.x,t.y,e),o.projectVectorToVector(L,t.spatialReference,L,E.renderCoordsHelper.spatialReference),S.setStartEndFromWorldDownAtLocation(L),V.intersectsWorldUpAtLocation=L}else i=!1;const c=C.grabbingState&u.GrabbingState.Z?h.settings.visualElements.laserlineAlphaMultiplier:1;c!==R&&(R=c,h.settings.visualElements.heightPlane.apply(P,c));const p=r.empty(A);!n&&l.displaying&&m.calculateMapBounds(p)&&o.projectVectorToVector(r.getMin(p,L),E.spatialReference,L,E.renderCoordsHelper.spatialReference)?(P.heightManifoldTarget=L,P.attached=!0):P.attached=!1;const d=C.grabbingState&u.GrabbingState.XY?h.settings.visualElements.laserlineAlphaMultiplier:1;d!==I&&(I=d,h.settings.visualElements.pointGraphics.shadowStyle.apply(V,d));const g=i&&l.displaying&&!n;V.attached=g,S.attached=g};c.push(i.watch((()=>[l.displaying,l.isDraped]),U),l.on("changed",U)),e.forEachManipulator((e=>{c.push(e.events.on("grab-changed",U))})),c.push(t.destroyHandle(V)),c.push(t.destroyHandle(S)),c.push(t.destroyHandle(P)),U()}function V(e,n,a){const{view:i,graphic:s}=e,l=new m.PointVisualElement({view:i,geometry:G(s),elevationInfo:p.getGraphicEffectiveElevationInfo(s),attached:!1});return M(e,l,n,a),a.push(t.destroyHandle(l)),l}function G(e){const t=e.geometry;return a.isNone(t)?null:"point"===t.type?t:"mesh"===t.type?t.anchor.clone():null}function M(e,t,n,a){const s=()=>t.attached=n.displaying;P(e,t,n,a),h.settings.visualElements.pointGraphics.outline.apply(t),a.push(i.watch((()=>n.displaying),s,i.initial))}function P(e,n,i,s){const{view:l,graphic:o}=e;let r=null;const c=e=>{a.isSome(r)&&(r.remove(),r=null),i.isDraped&&a.isSome(e)&&(r=x(l,e,(()=>{n.geometry=e})))},p=()=>{const e=G(o);c(e),n.geometry=e};s.push(i.on("changed",p),t.refHandle((()=>r))),p()}function x(e,t,n){const a=e.elevationProvider.spatialReference;o.projectPointToVector(t,L,a);const i=L[0],s=L[1];return e.elevationProvider.on("elevation-change",(e=>{c.containsXY(e.extent,i,s)&&n()}))}const L=l.create(),A=r.create();e.createVisualElements=b,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
