/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.24/esri/copyright.txt for details. */ import e from"../../Graphic.js";import"../../core/has.js";import{clone as n}from"../../core/lang.js";import{isNone as r}from"../../core/maybe.js";import{isFloat32Array as t,isFloat64Array as s,toArray as a}from"../../core/typedArrayUtil.js";import{fromJSON as i}from"../../geometry/support/jsonUtils.js";import{makeDehydratedPoint as o}from"./dehydratedFeatures.js";function m(e){return"declaredClass"in e}function u(e){return"declaredClass"in e}function l(e){return"declaredClass"in e}function c(r,t){if(!r)return null;if(l(r))return r;const s=new e({layer:t,sourceLayer:t});return s.visible=r.visible,s.symbol=n(r.symbol),s.attributes=n(r.attributes),s.geometry=f(r.geometry),s}function f(e){return r(e)?null:m(e)?e:i(h(e))}function h(e){const n=e.spatialReference.toJSON();switch(e.type){case"point":{const{x:r,y:t,z:s,m:a}=e;return{x:r,y:t,z:s,m:a,spatialReference:n}}case"polygon":{const{rings:r,hasZ:t,hasM:s}=e;return{rings:p(r),hasZ:t,hasM:s,spatialReference:n}}case"polyline":{const{paths:r,hasZ:t,hasM:s}=e;return{paths:p(r),hasZ:t,hasM:s,spatialReference:n}}case"extent":{const{xmin:r,xmax:t,ymin:s,ymax:a,zmin:i,zmax:o,mmin:m,mmax:u,hasZ:l,hasM:c}=e;return{xmin:r,xmax:t,ymin:s,ymax:a,zmin:i,zmax:o,mmin:m,mmax:u,hasZ:l,hasM:c,spatialReference:n}}case"multipoint":{const{points:r,hasZ:t,hasM:s}=e;return{points:M(r)?y(r):r,hasZ:t,hasM:s,spatialReference:n}}default:return}}function p(e){return x(e)?e.map((e=>y(e))):e}function y(e){return e.map((e=>a(e)))}function x(e){for(const n of e)if(0!==n.length)return M(n);return!1}function M(e){return e.length&&(t(e[0])||s(e[0]))}function Z(e,n){if(!e)return null;let r;if(u(e)){if(null==n)return e.clone();if(u(n))return n.copy(e)}return null!=n?(r=n,r.x=e.x,r.y=e.y,r.spatialReference=e.spatialReference,e.hasZ?(r.z=e.z,r.hasZ=e.hasZ):(r.z=null,r.hasZ=!1),e.hasM?(r.m=e.m,r.hasM=!0):(r.m=null,r.hasM=!1)):(r=o(e.x,e.y,e.z,e.spatialReference),e.hasM&&(r.m=e.m,r.hasM=!0)),r}export{Z as clonePoint,f as hydrateGeometry,c as hydrateGraphic,m as isHydratedGeometry,l as isHydratedGraphic,u as isHydratedPoint};