/*
All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
*/
import e from"../../../core/Error.js";import{getSupportedRendererTypes as r,getFunctionColorRamp as a,matchPresetRenderer as t,createDefaultRenderer as s,getDefaultBandCombination 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"},d=Object.keys(l).map(e=>l[e].label);function p(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 n=p((e=await y(e)).layer),i=await n.generateRasterInfo(e),o=r(i,!0).map(e=>c[e]),l=n.layer,d="imagery-tile"===l.type?a(l.raster):void 0,u="wcs"!==l.type?l.presetRenderers:void 0,m=t({variableName:e.variableName,rasterFunctionName:e.rasterFunction?.functionName,presetRenderers:u}),f=m?.renderer??s(i,{rasterFunctionColorRamp:d,variableName:e.variableName}),{bandCount:b}=i;return b>1&&o.push("raster-rgb"),!o.includes("raster-class-breaks")&&1===b&&+n.layer?.version>=10.3&&o.push("raster-class-breaks"),{supportedTypes:o,defaultRenderer:f}}async function m(e){const r=p((e=await y(e)).layer),a=await r.generateRasterInfo(e),{layer:s}=r;if("wcs"!==s.type&&s.presetRenderers?.length){const r=t({variableName:e.variableName,rasterFunctionName:e.rasterFunction?.functionName,presetRenderers:s.presetRenderers});if(r?.bandIds?.length)return r.bandIds}return n(a)}async function y(r){const{layer:a}=r;if(!a)throw new e("raster-renderer-creator:missing-parameters","'layer' parameter is required");const t=p(a);if(null==t)throw new e("raster-renderer-creator:invalid-parameters","'layer' must be one of these types: "+d.join(", "));await t.load();const s=r.rasterFunction??r.renderingRule??a.rasterFunction;return await t.updateRasterInfo({rasterFunction:s,signal:r.signal}),{...r,layer:t,rasterFunction:s}}export{p as createRasterLayerAdapter,m as getDefaultBandCombination,u as getSupportedRendererInfo,y as processRasterRendererParameters};
