/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["exports","../chunks/_rollupPluginBabelHelpers","../geometry","../request","../core/maybe","../geometry/support/normalizeUtils","./utils","./support/ImageAngleResult","./support/ImageIdentifyResult","./support/ImagePixelLocationResult","./support/ImageSampleResult","../geometry/SpatialReference"],(function(e,t,n,a,i,r,o,s,l,u,c,p){"use strict";function m(e){const t=null==e?void 0:e.time;if(t&&(null!=t.start||null!=t.end)){const n=[];null!=t.start&&n.push(t.start),null==t.end||n.includes(t.end)||n.push(t.end),e.time=n.join(",")}}function f(e,t,n){return d.apply(this,arguments)}function d(){return(d=t._asyncToGenerator((function*(e,t,n){const a=o.parseUrl(e),s=t.geometry?[t.geometry]:[],l=yield r.normalizeCentralMeridian(s),u=t.toJSON();m(u);const c=l&&l[0];i.isSome(c)&&(u.geometry=c.toJSON());const p=o.encode({...a.query,f:"json",...u});return o.asValidOptions(p,n)}))).apply(this,arguments)}function y(e,t,n){return g.apply(this,arguments)}function g(){return(g=t._asyncToGenerator((function*(e,t,n){var r;const l=t.toJSON();i.isSome(l.angleName)&&(l.angleName=l.angleName.join(",")),i.isSome(t.point)&&null!=(r=t.point.spatialReference)&&r.imageCoordinateSystem&&(l.point.spatialReference=T(t.point.spatialReference)),i.isSome(t.spatialReference)&&t.spatialReference.imageCoordinateSystem&&(l.spatialReference=U(t.spatialReference));const u=o.parseUrl(e),c=o.encode({...u.query,f:"json",...l}),m=o.asValidOptions(c,n),{data:f}=yield a(`${u.path}/computeAngles`,m);return f.spatialReference=f.spatialReference?null!=f.spatialReference.geodataXform?new p({wkid:0,imageCoordinateSystem:f.spatialReference}):p.fromJSON(f.spatialReference):null,"NaN"===f.north&&(f.north=null),"NaN"===f.up&&(f.up=null),new s(f)}))).apply(this,arguments)}function S(e,t,n){return h.apply(this,arguments)}function h(){return(h=t._asyncToGenerator((function*(e,t,n){const i=t.toJSON(),{geometries:r}=t;for(let a=0;a<r.length;a++){var s;null!=(s=r[a].spatialReference)&&s.imageCoordinateSystem&&(i.geometries.geometries[a].spatialReference=T(r[a].spatialReference))}const l=o.parseUrl(e),c=o.encode({...l.query,f:"json",...i}),p=o.asValidOptions(c,n),{data:m}=yield a(`${l.path}/computePixelLocation`,p);return u.fromJSON(m)}))).apply(this,arguments)}function N(e,t,n){return O.apply(this,arguments)}function O(){return(O=t._asyncToGenerator((function*(e,t,n){const i=yield f(e,t,n),r=o.parseUrl(e),{data:s}=yield a(`${r.path}/computeStatisticsHistograms`,i),{statistics:l}=s;return null!=l&&l.length&&l.forEach((e=>{e.avg=e.mean,e.stddev=e.standardDeviation})),{statistics:l,histograms:s.histograms}}))).apply(this,arguments)}function R(e,t,n){return J.apply(this,arguments)}function J(){return(J=t._asyncToGenerator((function*(e,t,n){const i=yield f(e,t,n),r=o.parseUrl(e),{data:s}=yield a(`${r.path}/computeHistograms`,i);return{histograms:s.histograms}}))).apply(this,arguments)}function v(e,t,n){return C.apply(this,arguments)}function C(){return(C=t._asyncToGenerator((function*(e,t,n){var s,l;const u=t.toJSON();m(u),null!=(s=u.outFields)&&s.length&&(u.outFields=u.outFields.join(","));const p=yield r.normalizeCentralMeridian(t.geometry),f=null==p?void 0:p[0];i.isSome(f)&&(u.geometry=f.toJSON());const d=o.parseUrl(e),y=o.encode({...d.query,f:"json",...u}),g=o.asValidOptions(y,n),{data:S}=yield a(`${d.path}/getSamples`,g),h=null==S||null==(l=S.samples)?void 0:l.map((e=>{const t="NaN"===e.value||""===e.value?null:e.value.split(" ").map((e=>Number(e)));return{...e,pixelValue:t}}));return c.fromJSON({samples:h})}))).apply(this,arguments)}function _(e,t,n){return j.apply(this,arguments)}function j(){return(j=t._asyncToGenerator((function*(e,t,n){const s=o.parseUrl(e),u=t.geometry?[t.geometry]:[];return r.normalizeCentralMeridian(u).then((e=>{const r=t.toJSON(),l=e&&e[0];i.isSome(l)&&(r.geometry=JSON.stringify(l.toJSON()));const u=o.encode({...s.query,f:"json",...r}),c=o.asValidOptions(u,n);return a(s.path+"/identify",c)})).then((e=>l.fromJSON(e.data)))}))).apply(this,arguments)}function T(e){const{imageCoordinateSystem:t}=e;if(t){const{id:e,referenceServiceName:n}=t;return null!=e?n?{icsid:e,icsns:n}:{icsid:e}:{ics:t}}return e.toJSON()}function U(e,t){const n=T(e),{icsid:a,icsns:i,wkid:r}=n;return null!=a?null==i||null!=t&&t.toLowerCase().includes("/"+i.toLowerCase()+"/")?`0:${a}`:JSON.stringify(n):r?r.toString():JSON.stringify(n)}e.computeAngles=y,e.computeHistograms=R,e.computePixelSpaceLocations=S,e.computeStatisticsHistograms=N,e.getImageSpatialReferenceJSON=T,e.getImageSpatialReferenceQueryParameter=U,e.getSamples=v,e.identify=_,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
