/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["../../../../chunks/_rollupPluginBabelHelpers","../../../../chunks/tslib.es6","../../../../geometry","../../../../core/maybe","../../../../core/accessorSupport/decorators/property","../../../../core/arrayUtils","../../../../core/has","../../../../core/accessorSupport/ensureType","../../../../core/accessorSupport/decorators/subclass","../../../../layers/support/rasterFunctions/stretchUtils","../../../../rest/support/ImageHistogramParameters","./RasterLayerAdapter","../../../../geometry/Point"],(function(e,t,s,r,i,a,n,o,l,u,c,p,h){"use strict";let d=function(t){function s(){var e;return(e=t.apply(this,arguments)||this)._cacheSize=20,e._statsCache=new Map,e}e._inheritsLoose(s,t);var i=s.prototype;return i.generateRasterInfo=function(e){const t=r.unwrap(null==e?void 0:e.renderingRule);return this.layer.generateRasterInfo(t,{signal:null==e?void 0:e.signal})},i.estimateStatisticsHistograms=function(){var t=e._asyncToGenerator((function*(e){var t,s,i;const a=null!=(t=null==(s=r.unwrap(null==e?void 0:e.renderingRule))?void 0:s.functionName)?t:"default";if(this._statsCache.has(a))return this._statsCache.get(a);let{width:n,height:o,pixelSize:l}=this.layer.rasterInfo,p=1;for(;n>2e3||o>2e3;)n/=2,o/=2,p*=2;const d=null!=(i=null==e?void 0:e.renderingRule)?i:this.layer.renderingRule,{fullExtent:g,mosaicRule:y}=this.layer;l=new h(l.x*p,l.y*p,g.spatialReference);const m=new c({geometry:g,pixelSize:l,renderingRule:d,mosaicRule:y});let f;if(this.layer.capabilities.operations.supportsComputeStatisticsHistograms)f=yield this.layer.computeStatisticsHistograms(m,e);else{const{histograms:t}=yield this.layer.computeHistograms(m,e);f={statistics:u.estimateStatisticsFromHistograms(t),histograms:t}}if(this._statsCache.set(a,f),this._statsCache.size>this._cacheSize){const e=this._statsCache.keys().next().value;this._statsCache.delete(e)}return f}));function s(e){return t.apply(this,arguments)}return s}(),i.supportsMultidirectionalHillshade=function(){return this.layer.version>=10.81},i.load=function(e){return this.addResolvingPromise(this.layer.load(e).then((()=>{var t;this.generateRasterInfo({renderingRule:this.renderingRule,signal:null==(t=r.unwrap(e))?void 0:t.signal}).then((e=>this.rasterInfo=e))}))),Promise.resolve(this)},s}(p);t.__decorate([i.property()],d.prototype,"layer",void 0),d=t.__decorate([l.subclass("esri.smartMapping.support.adapters.ImageryLayerAdapter")],d);return d}));
