import e from"@arcgis/core/geometry/Extent";import r from"@arcgis/core/portal/Portal";import i from"@arcgis/core/portal/PortalItem";import{isImageryLayer as a}from"../utilities/_layers.js";import{checkArg as o}from"../utilities/checkArg.js";import{deepClone as t}from"../utilities/object.js";import{LayerDefinition as p}from"./LayerDefinition.js";import{MosaicRule as n}from"./MosaicRule.js";import{PopupInfo as s}from"./PopupInfo.js";import{PixelType as l,RenderingRule as y}from"./RenderingRule.js";import{ERR_LAYER_TYPE_MISMATCH as m,applyLayerBaseToEsriApiLayer as c,applyBasemapLayerToEsriApiLayer as u,applyOperationalLayerToEsriApiLayer as f,fromEsriApiLayerToLayerBase as I,fromEsriApiLayerToOperationalLayer as g}from"./_layerHelper.js";export var ImageServiceLayer;!function(d){async function h(e,I,g){o("layerJson",e).isNotMissing(),o("layerJson.layerType",e.layerType).satisfies((e=>!e||"ArcGISImageServiceLayer"===e||"ArcGISImageServiceVectorLayer"===e),m),o("layer",I).isNotMissing().satisfies(a,m),c(e,I),u(e,I),f(e,I),e.hasOwnProperty("url")&&(I.url=e.url),e.hasOwnProperty("bandIds")&&(I.bandIds=t(e.bandIds)),e.hasOwnProperty("copyright")&&(I.copyright=e.copyright),e.hasOwnProperty("compressionQuality")&&(I.compressionQuality=e.compressionQuality),e.hasOwnProperty("format")&&null!=e.format&&(I.format=e.format),e.hasOwnProperty("itemId")&&(I.portalItem?I.portalItem.id=e.itemId:I.portalItem=new i({id:e.itemId,portal:g||r.getDefault()})),e.hasOwnProperty("mosaicRule")&&null!=e.mosaicRule&&(I.mosaicRule=n.toEsriApiMosaicRule(e.mosaicRule)),e.hasOwnProperty("noDataInterpretation")&&(I.noDataInterpretation="esriNoDataMatchAll"===e.noDataInterpretation?"all":"any"),e.hasOwnProperty("popupInfo")&&null!=e.popupInfo&&(I.popupTemplate=s.toEsriApiPopupTemplate(e.popupInfo)),e.hasOwnProperty("pixelType")&&null!=e.pixelType&&(I.pixelType=l.toEsriApiPixelType(e.pixelType)),e.hasOwnProperty("renderingRule")&&null!=e.renderingRule&&(I.rasterFunction=y.toEsriApiRasterFunction(e.renderingRule)),e.hasOwnProperty("layerDefinition")&&null!=e.layerDefinition&&await p.applyToEsriApiLayer(e.layerDefinition,I)}d.esriImageServiceLayerDefaults={popupEnabled:!0,visible:!0,opacity:1,wkid:4326,minScale:0,maxScale:0,fullExtent:new e({xmin:-180,ymin:-90,xmax:180,ymax:90,spatialReference:{wkid:4326}})},d.toEsriApiLayer=async function(e){o("layerJson",e).isNotMissing(),o("layerJson.layerType",e.layerType).satisfies((e=>!e||"ArcGISImageServiceLayer"===e||"ArcGISImageServiceVectorLayer"===e),m);const r=new((await import("@arcgis/core/layers/ImageryLayer")).default);return await h(e,r),r},d.applyToEsriApiLayer=h,d.fromEsriApiImageryLayer=function(e){o("layer",e).isNotMissing();const r={...I(e),...g(e),layerType:"ArcGISImageServiceLayer",url:e.url??void 0,layerDefinition:p.fromEsriApiLayer(e,d.esriImageServiceLayerDefaults)};return e.bandIds&&(r.bandIds=t(e.bandIds)),e.copyright&&(r.copyright=e.copyright),null==e.compressionQuality||isNaN(e.compressionQuality)||(r.compressionQuality=e.compressionQuality),e.format&&(r.format=e.format),e.portalItem&&(r.itemId=e.portalItem.id??void 0),e.mosaicRule&&(r.mosaicRule=n.fromEsriApiMosaicRule(e.mosaicRule)),e.noDataInterpretation&&(r.noDataInterpretation="all"===e.noDataInterpretation?"esriNoDataMatchAll":"esriNoDataMatchAny"),e.popupTemplate&&(r.popupInfo=s.fromEsriApiPopupTemplate(e.popupTemplate)),e.pixelType&&(r.pixelType=l.fromEsriApiPixelType(e.pixelType)),e.rasterFunction&&(r.renderingRule=y.fromEsriApiRasterFunction(e.rasterFunction)),r}}(ImageServiceLayer||(ImageServiceLayer={}));