/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
import{fetchMessageBundle as e}from"../../intl.js";import r from"../../core/Error.js";import{getAggregateFieldInfo as n,createLabelExpressionForAggregateField as t,createLabelClass as i}from"./support/utils.js";import{aggregateCountField as a}from"../support/binningUtils.js";async function o(e){const{layer:n,renderer:t}=e;if(await n.load(),"binning"!==n.featureReduction?.type)throw new r("bins-label-schemes:invalid-parameters","featureReduction type of the layer is not valid");const i=t||n.featureReduction.renderer;if(!i)throw new r("bins-label-schemes:invalid-parameters","'renderer' is not valid");return{layer:n,renderer:i}}async function s(e,r,a,o){const s=n(e,r);if(!s)return null;const l=t(r,a,s,o);return{name:`binning-${e}`,labelingInfo:[i(l,!0)],fieldName:e}}function l(e){let r=[];const n=e.featureReduction;return"fields"in n&&(r=n.fields.map(e=>e.name)),r}async function c(n){const[{renderer:t,layer:i},c]=await Promise.all([o(n),e("esri/smartMapping/t9n/smartMapping")]),f=c.clusters.predominantNoneValue;if(n.field){const e=await s(n.field,i,t,f);if(!e)throw new r("bins-label-schemes:invalid-parameters","'field' is not a valid aggregate field");return{primaryScheme:e,secondarySchemes:[]}}const m=await s(a,i),d=[],u=l(i).filter(e=>e.toLowerCase()!==a.toLowerCase());for(const e of u){const r=await s(e,i,t,f);r&&d.push(r)}return{primaryScheme:m,secondarySchemes:d}}export{c as getLabelSchemes};
