/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
import t from"../../../../core/Error.js";import{isLoadedSharedTemplate as e,isSharedFeatureTemplate as o,isSharedPresetTemplate as r}from"../../../templateUtils.js";import{createFeatureServiceEdit as i}from"./createFeatureServiceEdit.js";import{maxDigitizingDisplayEdits as s}from"./executorUtils.js";import n from"../../../../geometry/Multipoint.js";import p from"../../../../geometry/Point.js";import{execute as a}from"../../../../geometry/operators/affineTransformOperator.js";import f from"../../../../geometry/operators/support/Transformation.js";import{getPaths as m,getEndpoint as l}from"../../../../geometry/support/curves/curveUtils.js";function c({edits:n,geometry:p,mode:m,relationships:l,rotation:g,tag:u="",template:y}){const{definition:d}=y,j=p.x-d.origin.x,Z=p.y-d.origin.y,x=d.origin.hasZ&&p.hasZ?p.z-d.origin.z:0,w=h(d.origin.clone(),j,Z,x),M=(new f).rotate(g,w.x,w.y);for(const f of d.parts){if(n.length>s&&"digitizing"===m)break;const g=f.template;if(!e(g))throw new t("shared-template:template-not-loaded","A template part's template must be loaded before use");if(o(g)){let t=h(f.geometry,j,Z,x);M.isIdentity()||(t=a(t,M)),i({edits:n,geometry:t,relationships:l,tag:u,template:g})}else if(r(g)){const t=[];if(c({edits:M.isIdentity()?t:n,geometry:p,mode:m,relationships:l,rotation:0,tag:u,template:g}),!M.isIdentity())for(const e of t){const{geometry:t}=e.graphic;t&&"mesh"!==t.type&&(e.graphic.geometry=a(t,M),n.push(e))}}}return w}function h(t,e,o,r=0){if(!t)return null;if("point"===t.type)return new p({spatialReference:t.spatialReference,x:t.x+e,y:t.y+o,...t.hasZ?{z:t.z+r}:{},...t.hasM?{m:t.m}:{}});if("multipoint"===t.type){const i=[];if(t.hasZ&&t.hasM)for(let s=0;s<t.points.length;s++){const n=t.points[s];i.push([n[0]+e,n[1]+o,n[2]+r,n[3]])}else if(t.hasZ)for(let s=0;s<t.points.length;s++){const n=t.points[s];i.push([n[0]+e,n[1]+o,n[2]+r])}else if(t.hasM)for(let r=0;r<t.points.length;r++){const s=t.points[r];i.push([s[0]+e,s[1]+o,s[2]])}else for(let r=0;r<t.points.length;r++){const s=t.points[r];i.push([s[0]+e,s[1]+o])}return new n({spatialReference:t.spatialReference,hasZ:t.hasZ,hasM:t.hasM,points:i})}if("polygon"===t.type||"polyline"===t.type){const i=g(t,e,o);return 0!==r&&t.hasZ&&u(i,r),i}return t.clone()}function g(t,e,o){const r=new f;return r.shift(e,o),a(t,r)}function u(t,e){for(const o of m(t))for(const t of o){l(t)[2]+=e}}export{c as createPresetServiceEdit,h as translate};
