/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
import{getHeightUnitCorrectionFactor as t}from"../../../geometry/coordUtils.js";import{segmentLength3d as e}from"../../../geometry/lineUtils.js";import{readOffsetDistance as r,readIsProportional as s,readVertexBeforeOffset as o,readDistance as n,makeFeatureFromGroupPart as i}from"./support/builderUtils.js";import{offset as a}from"./support/offsetUtils.js";import{pointAlongLineWithZAndOffset as p,pointAlongLineAndOffset as l,offsetPointFromSegment as f}from"./support/shapeUtils.js";import{isPolyline as c,maxDigitizingDisplayEdits as m}from"../support/executorUtils.js";import h from"../../../../geometry/Multipoint.js";import{e as u}from"../../../../chunks/intersectsOperator.js";import{fromSpatialReference as g}from"../../../../geometry/operators/support/apiConverter.js";import{getLength as y}from"../../../../geometry/support/coordsUtils.js";function d(t){if(U(t)&&"digitizing"!==t.mode)return j(t)}async function j({templatePart:c,parentTemplate:h,shape:d,edits:j,relationships:U,mode:b}){const{builderConfig:M}=c,Z=r(M),P=s(M),T=o(M),V=n(M,P),k=T||0===Z?d:a(d,Z);if(null===k)return;const w=h.layer.createQuery();w.geometry=k,w.spatialRelationship="intersects",w.returnM=!0,w.returnZ=!0,w.outSpatialReference=k.spatialReference,w.cacheHint=!1,w.returnGeometry=!0,w.historicMoment=h.layer.historicMoment,w.gdbVersion=h.layer.gdbVersion;const x=2*(g(k.spatialReference)?.getTolerance()??.001);w.distance=x;const{features:C}=await h.layer.queryFeatures(w);if(0===C.length)return;const S=[];for(const t of C)S.push(R(t.geometry));const q=t(k.spatialReference);let v=0,z=0;for(let t=0;t<k.paths.length&&!(j.length>m);t++){const r=k.paths[t].length;for(let s=0;s<r;s++){let o=k.getPoint(t,s);if(null!=o){for(const n of S)if(u(o,n)){if(s>0&&0!==V&&(v+=k.hasZ?e(k.paths[t][s-1],k.paths[t][s],q):y(k.paths[t][s-1],k.paths[t][s])),0!==V){let n=1;if(P){const o=V<0?s-1:s+1;if(o>=r||o<0)return;n=k.hasZ?e(k.paths[t][s],k.paths[t][o],q):y(k.paths[t][s],k.paths[t][o])}const i=v+n*V;o=k.hasZ?p(k,i,Z,q):l(k,i,Z)}else 0!==Z&&(o=f(o,s===r-1?[k.paths[t][s-1],k.paths[t][s]]:[k.paths[t][s],k.paths[t][s+1]],Z));o&&i({templatePart:c,shape:o,edits:j,relationships:U,mode:b},`V${z.toString()}`);break}z++}}}}function R(t){const e=[];for(const r of t.paths)for(const t of r)e.push([...t]);return new h({spatialReference:t.spatialReference,points:e})}function U(t){return null!=t.parentTemplate&&c(t.shape)}const b=!0;export{d as execute,b as isAsync};
