/*
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","../../../../Graphic","../../../../core/Accessor","../../../../core/Logger","../../../../core/maybe","../../../../core/promiseUtils","../../../../core/accessorSupport/decorators/property","../../../../core/arrayUtils","../../../../core/has","../../../../core/accessorSupport/ensureType","../../../../core/accessorSupport/decorators/subclass","../../../../layers/support/rasterFunctions/pixelUtils","../../engine/BitmapContainer","../../engine/Container","../../engine/ImageryBitmapSource","../support/ExportStrategy"],(function(e,t,r,i,a,o,s,n,p,c,l,u,d,h,y,g,m){"use strict";const x=a.getLogger("esri.views.2d.layers.imagery.ImageryView2D");let _=function(t){function i(){var e;return(e=t.apply(this,arguments)||this).attached=!1,e.container=new y.Container,e.updateRequested=!1,e.type="imagery",e._bitmapView=new h.BitmapContainer,e}e._inheritsLoose(i,t);var a=i.prototype;return a.destroy=function(){this.attached&&(this.detach(),this.attached=!1),this.updateRequested=!1},a.update=function(e){this.strategy.update(e).catch((e=>{s.isAbortError(e)||x.error(e)}))},a.hitTest=function(e){return new r({attributes:{},geometry:e.clone(),layer:this.layer})},a.attach=function(){this.container.addChild(this._bitmapView);const e=this.layer.version>=10,t=this.layer.version>=10.1?this.layer.imageMaxHeight:2048,r=this.layer.version>=10.1?this.layer.imageMaxWidth:2048;this.strategy=new m({container:this._bitmapView,imageNormalizationSupported:e,imageMaxHeight:t,imageMaxWidth:r,fetchSource:this._fetchImage.bind(this),requestUpdate:()=>this.requestUpdate()})},a.detach=function(){this.strategy.destroy(),this._bitmapView.removeAllChildren(),this.container.removeAllChildren(),this.updateRequested=!1},a.redraw=function(){this.strategy.updateExports((e=>{e.source instanceof HTMLImageElement?e.requestRender():this.layer.applyRenderer({pixelBlock:e.source.pixelBlock}).then((t=>{const r=e.source;r.pixelBlock=t.pixelBlock,r.filter=e=>this.layer.applyFilter(e),this.container.requestRender()}))}))},a.requestUpdate=function(){this.updateRequested||(this.updateRequested=!0,this.view.requestUpdate())},a.isUpdating=function(){return this.strategy.updating||this.updateRequested},a.getPixelData=function(){if(this.updating)return null;const e=this.strategy.bitmaps;if(1===e.length&&e[0].source)return{extent:e[0].source.extent,pixelBlock:e[0].source.originalPixelBlock};if(e.length>1){const t=this.view.extent,r=e.map((e=>e.source)).filter((e=>e.extent&&e.extent.intersects(t))).map((e=>({extent:e.extent,pixelBlock:e.originalPixelBlock}))),i=d.mosaicPixelData(r,t);return o.isSome(i)?{extent:i.extent,pixelBlock:i.pixelBlock}:null}return null},a._fetchImage=function(e,t,r,i){return(i=i||{}).timeExtent=this.timeExtent,i.requestAsImageElement=!0,this.layer.fetchImage(e,t,r,i).then((e=>e.imageElement?e.imageElement:this.layer.applyRenderer(e.pixelData,{signal:i.signal}).then((t=>{const r=new g(t.pixelBlock,t.extent.clone(),e.pixelData.pixelBlock);return r.filter=e=>this.layer.applyFilter(e),r}))))},e._createClass(i,[{key:"updating",get:function(){return!this.attached||this.isUpdating()}}]),i}(i);t.__decorate([n.property()],_.prototype,"attached",void 0),t.__decorate([n.property()],_.prototype,"container",void 0),t.__decorate([n.property()],_.prototype,"layer",void 0),t.__decorate([n.property()],_.prototype,"strategy",void 0),t.__decorate([n.property()],_.prototype,"timeExtent",void 0),t.__decorate([n.property()],_.prototype,"view",void 0),t.__decorate([n.property()],_.prototype,"updateRequested",void 0),t.__decorate([n.property()],_.prototype,"updating",null),t.__decorate([n.property()],_.prototype,"type",void 0),_=t.__decorate([u.subclass("esri.views.2d.layers.imagery.ImageryView2D")],_);return _}));
