/*
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","../../../../support/elevationInfoUtils","../Manipulator3D","./GrabbingState","./ManipulatorState","./ManipulatorType","./settings","../visualElements/ExtendedLineVisualElement","../visualElements/LaserlineVisualElement","../visualElements/OutlineVisualElement","../../layers/graphics/GraphicState","../../webgl-engine/lib/Material"],(function(e,t,n,a,i,l,s,r,o,c,d,u,p,h,g,m,v,E){"use strict";function y(e){const{view:n,graphic:a}=e,i=new v.GraphicState({graphic:a}),l=f(e,i),s=[l,S(e,l.visualElement,i),n.maskOccludee(a),n.trackGraphicState(i)];return{visualElement:l.visualElement,remove:()=>t.handlesGroup(s).remove()}}function f(e,n){const{view:a,graphic:l}=e,s=new m.OutlineVisualElement({view:a,geometry:G(l)?l.geometry:null,elevationInfo:r.getGraphicEffectiveElevationInfo(l),attached:!1});p.settings.visualElements.lineGraphics.shadowStyle.apply(s);const o=()=>{s.attached=n.displaying};p.settings.visualElements.lineGraphics.outline.apply(s);const c=[i.watch((()=>n.displaying),o),i.watch((()=>n.isDraped),(e=>{s.isDraped=e})),n.on("changed",(()=>s.geometry=G(l)?l.geometry:null)),t.destroyHandle(s)];return o(),{visualElement:s,remove:()=>t.handlesGroup(c).remove()}}function S(e,a,l){const{graphic:s,view:o}=e,u=[],m=r.getGraphicEffectiveElevationInfo(s),v="on-the-ground"===m.mode||!m.offset&&"absolute-height"!==m.mode,y=new d.ManipulatorState,f=new h.ExtendedLineVisualElement({view:o,extensionType:p.settings.visualElements.zVerticalLine.extensionType,innerWidth:1,attached:!1,writeDepthEnabled:!1,renderOccluded:E.RenderOccludedFlag.OccludeAndTransparent});p.settings.visualElements.pointGraphics.shadowStyle.apply(f);const S=n.deg2rad(p.settings.visualElements.heightPlaneAngleCutoff),M=new g.LaserlineVisualElement({view:o,attached:!1,angleCutoff:S});p.settings.visualElements.heightPlane.apply(M);let L=1,T=1;const V=()=>{if(y.update(e),!l.displaying||v&&(l.isDraped||!G(s)||!s.geometry.hasZ))return a.laserlineEnabled=!1,f.attached=!1,void(M.attached=!1);a.laserlineEnabled=!0;{const e=y.grabbingState&c.GrabbingState.XY?p.settings.visualElements.laserlineAlphaMultiplier:1;e!==L&&(L=e,p.settings.visualElements.lineGraphics.shadowStyle.apply(a,e),p.settings.visualElements.pointGraphics.shadowStyle.apply(f,e))}{const e=y.grabbingState&c.GrabbingState.Z?p.settings.visualElements.laserlineAlphaMultiplier:1;e!==T&&(T=e,p.settings.visualElements.heightPlane.apply(M,e))}b(f,y),w(e,a,M,y)};p.settings.visualElements.zVerticalLine.apply(f),u.push(l.on("changed",V),i.watch((()=>l.displaying),V),a.events.on("attachment-origin-changed",V),t.destroyHandle(f),t.destroyHandle(M));const O=[],A=()=>{t.handlesGroup(O).remove(),O.length=0,e.forEachManipulator((e=>O.push(e.events.on("grab-changed",V)))),e.forEachManipulator((e=>O.push(e.events.on("select-changed",V)))),V()};return A(),u.push(e.onManipulatorsChanged(A),t.refHandle((()=>t.handlesGroup(O)))),t.handlesGroup(u)}function b(e,t){const n=1===t.numSelected?t.firstSelected:t.numSelected>1&&a.isSome(t.firstGrabbedXY)?t.firstGrabbedXY:null;a.isSome(n)?(e.setStartEndFromWorldDownAtLocation(n.renderLocation),e.attached=!0):e.attached=!1}function w(e,t,n,i){if(i.numSelected>0){l.set(M,0,0,0);let t=0;e.forEachManipulator(((e,n)=>{n===u.ManipulatorType.TRANSLATE_XY&&e.selected&&e instanceof o.Manipulator3D&&(l.add(M,M,e.renderLocation),t++)})),t>0?(n.heightManifoldTarget=l.scale(M,M,1/t),n.attached=!0):n.attached=!1}else{const i=t.attachmentOrigin;a.isSome(i)&&e.view.renderCoordsHelper.toRenderCoords(i,M)?(n.heightManifoldTarget=M,n.attached=!0):n.attached=!1}}function G(e){return a.isSome(e.geometry)&&("polygon"===e.geometry.type||"polyline"===e.geometry.type)}const M=s.create();e.createGeometryRepresentationVisualElement=f,e.createVisualElements=y,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
