/* COPYRIGHT Esri - https://js.arcgis.com/5.1.0/LICENSE.txt */
import e from"../../../core/Error.js";import{matchPresetRenderer as r,getDefaultBandCombination as a,getSupportedRendererTypes as t,getFunctionColorRamp as s,createDefaultRenderer as n}from"../../../renderers/support/rasterRendererHelper.js";import i from"./adapters/ImageryLayerAdapter.js";import o from"./adapters/ImageryTileLayerAdapter.js";const l={imagery:{adapter:i,label:"ImageryLayer"},"imagery-tile":{adapter:o,label:"ImageryTileLayer"},wcs:{adapter:o,label:"WCSLayer"}},c={"raster-stretch":"raster-stretch","unique-value":"raster-unique-value","raster-rgb":"raster-rgb","class-breaks":"raster-class-breaks","raster-colormap":"raster-colormap","raster-shaded-relief":"raster-shaded-relief","vector-field":"raster-vector-field",flow:"raster-flow"},p=Object.keys(l).map(e=>l[e].label);function d(e){if("raster-layer-adapter"===e.type)return e;const r=l[e.type]?.adapter;return null==r?null:new r({layer:e})}async function u(e){const a=d((e=await y(e)).layer),i=await a.generateRasterInfo(e),o=t(i,!0).map(e=>c[e]),l=a.layer,p="imagery-tile"===l.type?s(l.raster):void 0,u="wcs"!==l.type?l.presetRenderers:void 0,m=r({variableName:e.variableName,rasterFunctionName:e.rasterFunction?.functionName,presetRenderers:u}),f=m?.renderer??n(i,{rasterFunctionColorRamp:p,variableName:e.variableName}),{bandCount:b}=i;return b>1&&o.push("raster-rgb"),!o.includes("raster-class-breaks")&&1===b&&+a.layer?.version>=10.3&&o.push("raster-class-breaks"),{supportedTypes:o,defaultRenderer:f}}async function m(e){const t=d((e=await y(e)).layer),s=await t.generateRasterInfo(e),{layer:n}=t;if("wcs"!==n.type&&n.presetRenderers?.length){const a=r({variableName:e.variableName,rasterFunctionName:e.rasterFunction?.functionName,presetRenderers:n.presetRenderers});if(a?.bandIds?.length)return a.bandIds}return a(s)}async function y(r){const{layer:a}=r;if(!a)throw new e("raster-renderer-creator:missing-parameters","'layer' parameter is required");const t=d(a);if(null==t)throw new e("raster-renderer-creator:invalid-parameters","'layer' must be one of these types: "+p.join(", "));await t.load();const s=r.rasterFunction??a.rasterFunction;return await t.updateRasterInfo({rasterFunction:s,signal:r.signal}),{...r,layer:t,rasterFunction:s}}export{d as createRasterLayerAdapter,m as getDefaultBandCombination,u as getSupportedRendererInfo,y as processRasterRendererParameters};
