/* COPYRIGHT Esri - https://js.arcgis.com/5.1.0/LICENSE.txt */
import e from"../../../layers/support/LabelClass.js";import n from"../../../layers/support/LabelExpressionInfo.js";import o from"../../../renderers/support/UniqueValueInfo.js";import{getPredominantTypeExpression as t}from"../../support/clusterUtils.js";import l from"../../../symbols/TextSymbol.js";function r(e,n){const o=n.featureReduction;if("fields"in o)for(const t of o.fields)if(t.name.toLowerCase()===e.toLowerCase())return t;return null}function a(e){return`\n  $feature["${e}"];\n  var value = $feature["${e}"];\n  var num = Count(Text(Round(value)));\n  var label = When(\n    num < 4, Text(value, "#.#"),\n    num == 4, Text(value / Pow(10, 3), "#.0k"),\n    num <= 6, Text(value / Pow(10, 3), "#k"),\n    num == 7, Text(value / Pow(10, 6), "#.0m"),\n    num > 7, Text(value / Pow(10, 6), "#m"),\n    Text(value, "#,###")\n  );\n  return label;\n  `}function u(e,n,l,r){const u=l.name;if("mode"===l.statisticType){const a="getFieldDomain"in e?e.getFieldDomain(l.onStatisticField):null;let s=null;return"coded-value"===a?.type?s=a.codedValues.map(e=>new o({value:e.code,label:e.name})):"unique-value"===n?.type&&null!=n.field&&n.field.toLowerCase()===u.toLowerCase()&&(s=(n.uniqueValueInfos??[]).map(e=>e.clone())),s?t(s,u,r):`Text($feature["${u}"])`}return a(u)}function s(o,t=!1){const r=new l({haloColor:"#373837",haloSize:"1px",color:"#f0f0f0",font:{family:"Noto Sans",size:"12px",weight:"bold"}});return new e({symbol:r,deconflictionStrategy:"none",labelPlacement:t?"always-horizontal":"center-center",labelExpressionInfo:new n({expression:o})})}export{s as createLabelClass,u as createLabelExpressionForAggregateField,a as createNumericLabelExpression,r as getAggregateFieldInfo};
