/* 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 a,makeFeatureFromGroupPart as i}from"./support/builderUtils.js";import{offset as n}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 u from"../../../../geometry/Multipoint.js";import{e as h}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:u,shape:d,edits:j,relationships:U,mode:b,associationFeaturesByTemplate:T}){const{builderConfig:M}=c,Z=r(M),F=s(M),P=o(M),V=a(M,F),k=P||0===Z?d:n(d,Z);if(null===k)return;const w=u.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=u.layer.historicMoment,w.gdbVersion=u.layer.gdbVersion;const x=2*(g(k.spatialReference)?.getTolerance()??.001);w.distance=x;const{features:B}=await u.layer.queryFeatures(w);if(0===B.length)return;const C=[];for(const t of B)C.push(R(t.geometry));const S=t(k.spatialReference);let q=0,v=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 a of C)if(h(o,a)){if(s>0&&0!==V&&(q+=k.hasZ?e(k.paths[t][s-1],k.paths[t][s],S):y(k.paths[t][s-1],k.paths[t][s])),0!==V){let a=1;if(F){const o=V<0?s-1:s+1;if(o>=r||o<0)return;a=k.hasZ?e(k.paths[t][s],k.paths[t][o],S):y(k.paths[t][s],k.paths[t][o])}const i=q+a*V;o=k.hasZ?p(k,i,Z,S):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,associationFeaturesByTemplate:T},`V${v.toString()}`);break}v++}}}}function R(t){const e=[];for(const r of t.paths)for(const t of r)e.push([...t]);return new u({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};
