/*
All material copyright Esri, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
*/
import{unique as n}from"../../core/arrayUtils.js";import{createMD5Hash as e}from"../../core/MD5.js";import{isValidNumber as i}from"../../renderers/visualVariables/support/sizeVariableUtils.js";import{getPrimaryVisualVariables as t}from"../popup/support/utils.js";import{getNormalizationType as o}from"./utils.js";const l="cluster_count";function r(n,e){return n.split(`cluster_${e}_`).pop()}function a(n){if(!n)return null;const{field:e,valueExpression:t,normalizationField:l,normalizationType:r,normalizationTotal:a}=n;let u=null;if(t)u=t;else if(e){const n=o({normalizationType:r,normalizationField:l,normalizationTotal:a});if(n){const t=n.toLowerCase();if(u=e.toLowerCase()+",norm:"+t,l)u+=","+l.toLowerCase();else if("percent-of-total"===t){let n=a;i(n)&&0!==n||(n=null),u+=","+n}}}return u}function u(n){return e(n)}function s(n,e){const i=a(n);return`${e}_${null!=i?u(i):n.field}`}function p(n,e){return`cluster_${s(n,e)}`}function f(n,e){const i=e.getField(n);return i?.type}function c(n,e){const i="field"in e?e.field:null,t=i?f(i,n):null;return{field:i,fieldType:null!=t?t:null,valueExpression:"valueExpression"in e?e.valueExpression:null,valueExpressionTitle:"valueExpressionTitle"in e?e.valueExpressionTitle:null,normalizationField:"normalizationField"in e?e.normalizationField:null,normalizationType:"normalizationType"in e?e.normalizationType:null,normalizationTotal:"normalizationTotal"in e?e.normalizationTotal:null}}function m(n,e){const i="rotation"===e.type?e.rotationType:null,t=e.legendOptions?.title,o=e.field,l=o?f(o,n):null;return{field:o,fieldType:null!=l?l:null,rotationType:i,valueExpression:e.valueExpression,valueExpressionTitle:e.valueExpressionTitle||e.valueExpression&&t,normalizationField:"normalizationField"in e?e.normalizationField:null,vvType:e.type}}function v(n){return n.map(n=>`{\n        "value": "${String(n.value)}",\n        "label": "${T(String(n.label))}"\n      }`)}function T(n){return n?n.replaceAll('"','\\"'):""}function d(n,e,i){return`\n  var uvInfos = [${v(n).join(", ")}];\n  var predominantType = Text($feature["${e}"]);\n  var label = "${T(i)}";\n\n  for (var i = 0; i < Count(uvInfos); i++) {\n    if (uvInfos[i].value == predominantType) {\n      label = uvInfos[i].label;\n      break;\n    }\n  }\n\n  return label;\n  `}function y(n,e){const i=[s(n,e)];return"date"===n.fieldType&&i.push(n.fieldType.toLowerCase()),n.rotationType&&i.push(n.rotationType.toLowerCase()),i.join("_")}function z(n,e){return{statisticHash:y(n,e),attributeInfo:n,statisticType:e}}function x(e,i,o=!0){const l=[],r=c(e,i);"class-breaks"===i.type?l.push(z(r,"avg")):"unique-value"===i.type&&l.push(z(r,"type"));const a=t(i);for(const n of a){const i=m(e,n);l.push(z(i,"avg"))}return o?n(l,(n,e)=>n.statisticHash===e.statisticHash):l}export{l as clusterCountField,p as getClusterField,r as getClusterFieldHash,d as getPredominantTypeExpression,c as getRendererAttributeInfo,s as getStatisticId,z as getStatisticInfo,x as getStatisticInfos,m as getVariableAttributeInfo};
