/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
import e from"../../../../../core/Error.js";import{isLoadedSharedTemplate as t,isSharedPresetTemplate as o,isSharedFeatureTemplate as r}from"../../../../templateUtils.js";import{createFeatureServiceEdit as n}from"../../support/createFeatureServiceEdit.js";import{createPresetServiceEdit as s}from"../../support/createPresetServiceEdit.js";import a from"../../../../../geometry/Polygon.js";import{isPoint as i,isPolygon as u}from"../../../../../geometry/support/jsonTypeUtils.js";import{getPaths as l,getEndpoint as c,isCurvedGeometry as f,cloneCurve as p}from"../../../../../geometry/support/curves/curveUtils.js";function m({edits:a,mode:u,relationships:l,shape:c,templatePart:f},p=""){if(null===f)return;const{template:m}=f;if(!t(m))throw new e("shared-template:template-not-loaded","A template part's template must be loaded before use");if(o(m)){if(!i(c))throw new e("shared-template:invalid-geometry","Preset templates must have a point geometry");s({geometry:c,template:m,edits:a,relationships:l,rotation:0,mode:u,tag:p})}else r(m)&&n({geometry:c,template:m,edits:a,relationships:l,tag:p})}function h(e,t){if(!e||!u(e))return null;if(!t.hasZ&&!t.hasM)return e;let o=null,r=null;const n=t.hasZ&&t.hasM?3:2;switch(t.type){case"point":o=t.hasZ?t.z:null,r=t.hasM?t.m:null;break;case"polygon":case"polyline":{const e=l(t);for(const s of e)for(const e of s){const s=c(e);t.hasZ&&(null===o||s[2]>o)&&(o=s[2]),t.hasM&&(null===r||s[n]>r)&&(r=s[n])}}break;case"multipoint":for(const e of t.points)t.hasZ&&(null===o||e[2]>o)&&(o=e[2]),t.hasM&&(null===r||e[n]>r)&&(r=e[n]);break;default:return e}return f(e)?new a({curveRings:R(e.curveRings,t.hasZ,t.hasM,o,r),spatialReference:e.spatialReference,hasZ:t.hasZ,hasM:t.hasM}):new a({rings:j(e.rings,t.hasZ,t.hasM,o,r),spatialReference:e.spatialReference,hasZ:t.hasZ,hasM:t.hasM})}function d(e){let t=!1;return void 0!==e.byNumber&&(t=!0===e.byNumber),t}function g(e){let t=0;return void 0!==e.count&&(t=e.count),t}function v(e,t){let o=0;return t?void 0!==e.proportional&&(o=e.proportional):void 0!==e.distanceValue&&(o=e.distanceValue),t&&(o/=100),o}function y(e){return!0===e.isProportional}function M(e){return!1!==e.createUnique}function Z(e){let t=0;return void 0!==e.offsetDistance&&(t=e.offsetDistance),void 0!==e.side&&1===e.side&&(t*=-1),t}function b(e){return!0===e.vertexBeforeOffset}function j(e,t,o,r,n){const s=[];for(const a of e)s.push(w(a,t,o,r,n));return s}function w(e,t,o,r,n){const s=[];for(const a of e){const e=[a[0],a[1]];t&&(e[2]=r),o&&(e[t?3:2]=n),s.push(e)}return s}function R(e,t,o,r,n){const s=[];for(const a of e)s.push(P(a,t,o,r,n));return s}function P(e,t,o,r,n){const s=[];for(const a of e){const e=p(a),i=c(e);t&&(i[2]=r),o&&(i[t?3:2]=n),s.push(e)}return s}export{h as correctZandMFollowingBuffer,m as makeFeatureFromGroupPart,d as readByNumber,g as readCount,v as readDistance,y as readIsProportional,M as readIsUnique,Z as readOffsetDistance,b as readVertexBeforeOffset};
