/* COPYRIGHT Esri - https://js.arcgis.com/5.1.0/LICENSE.txt */
import e from"../../../core/Error.js";import{formatNumber as r}from"../../../intl/number.js";import{createClassBreaksRenderer as a,getField as t,getVariableRasterInfo as s}from"../../../renderers/support/rasterRendererHelper.js";import{processRasterRendererParameters as n}from"../support/utils.js";function o(e){const{rasterInfo:r,layer:a}=e,t=r.multidimensionalInfo?"imagery"===a.type?a.mosaicRule?.multidimensionalDefinition?.[0]?.variableName:a.multidimensionalDefinition?.[0]?.variableName:"";return s(r,t)}async function i(r){const a=o((r=await n(r)).layer);if(a.bandCount>1)throw new e("raster-class-breaks-renderer:not-supported","Multiband raster is not supported");const{attributeTable:s}=a;r.field||(r.field=t(s,"value")?.name??"value");const{colors:i,numClasses:l}=r;if(i&&l&&i.length!==l)throw new e("raster-class-breaks-renderer:not-supported","The size of the `colors` parameter does not match 'numClasses'");return r.classificationMethod||(r.classificationMethod="natural-breaks"),r}async function l(r){const t=o((r=await i(r)).layer).clone(),s=t.attributeTable?.fields.find(e=>e.name.toLowerCase()===r.field?.toLowerCase());if(!s&&!t.histograms?.length&&(await r.layer.updateRasterInfoWithEstimatedStats(t,{rasterFunction:r.rasterFunction,signal:r.signal}),!t.histograms?.length))throw new e("raster-class-breaks-renderer:not-supported","Histograms or raster attribute table is required on the source raster. Unable to estimate histograms");const n=a(t,r);if(null==n)throw new e("raster-class-breaks-renderer:not-supported","Class breaks renderer is not supported on this data");const l={minValue:n.minValue,maxValue:n.classBreakInfos[n.classBreakInfos.length-1].maxValue,normalizationTotal:null,classBreakInfos:n.classBreakInfos.map(e=>{const r=u(e.minValue,e.maxValue);return e.label=r,{minValue:e.minValue,maxValue:e.maxValue,label:r}})};return{renderer:n,classBreaksResult:l}}function u(e,a){return r(e,{maximumFractionDigits:3})+" - "+r(a,{maximumFractionDigits:3})}export{l as createRenderer};
