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