/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["exports","../../../../chunks/_rollupPluginBabelHelpers","../../../../core/promiseUtils","../../../statistics/support/predominanceUtils","../../utils","../../../../statistics/utils"],(function(e,t,n,o,a,i){"use strict";const r=/_value$/i,l=Math.LOG10E;function u(e){return e.map((e=>e.toJSON()))}function s(e,t,n){return c.apply(this,arguments)}function c(){return(c=t._asyncToGenerator((function*(e,t,n){const o=[];if(t)for(const a of t){const t=e.getField(a);"availableFields"in n&&!n.availableFields.includes(t.name)&&o.push(t.name)}return o}))).apply(this,arguments)}function f(e,t){const n=e&&e.features,o=n&&n[0]&&n[0].attributes,a={};for(const i in o)a[i.replace(r,"").toLowerCase()]=o[i];return null!=a.totalcount&&a.totalcount>=a.count&&(a.nullcount=a.totalcount-a.count),delete a.totalcount,a.min===a.max&&null!=a.min&&null==a.stddev&&(a.stddev=a.variance=0),t&&(["min","max","avg","stddev","sum","variance"].forEach((e=>{null!=a[e]&&(a[e]=Math.ceil(a[e]))})),a.min===a.max&&null!=a.min&&(a.avg=a.min,a.stddev=a.variance=0)),a}function m(e){const t=[],n=e.classBreaks,o=n[0].minValue,a=n[n.length-1].maxValue;n.forEach((e=>{t.push([e.minValue,e.maxValue])}));const i={field:e.field,normalizationType:e.normalizationType,normalizationField:e.normalizationField,normalizationTotal:e.normalizationTotal,layer:e.layer};return{min:o,max:a,intervals:t,sqlExpr:d(i),excludeZerosExpr:e.where,normTotal:e.normalizationTotal}}function d(e){const{field:t,normalizationType:n,normalizationField:o,normalizationTotal:i,layer:r}=e,u=a.isIntegerField(r,t);let s=t;return"percent-of-total"===n?s=`((${u?a.castIntegerFieldToFloat(t):t} / ${i}) * 100)`:"log"===n?s=`(log(${t}) * ${l})`:"field"===n?s=`(${u?a.castIntegerFieldToFloat(t):t} / ${o})`:"natural-log"===n?s=`(log(${u?a.castIntegerFieldToFloat(t):t}))`:"square-root"===n&&(s=`(power(${u?a.castIntegerFieldToFloat(t):t}, 0.5))`),s}function p(e,t){let n;if(t=t.toLowerCase(),e)for(const o in e)if(o.toLowerCase()!==t){n=e[o];break}return n}function g(e,t){let n;if(t=t.toLowerCase(),e)for(const o in e)if(o.toLowerCase()===t){n=e[o];break}return n}function F(e,t,n,o,a){const r={},l="countOFExpr";e&&e.features&&e.features.forEach((e=>{const t=e.attributes,n=p(t,l),o=g(t,l);0!==n&&(r[n]=o)}));const u=[];return i.getEqualIntervalBins(t,n,o).forEach(((e,t)=>{const n=(t+1).toString();u.push({minValue:e[0],maxValue:e[1],count:r.hasOwnProperty(n)?r[n]:0})})),{bins:u,minValue:t,maxValue:n,normalizationTotal:a}}function v(e,t,o,a,i,r){const l=e&&e.features,u="countOF"+(o||"Expr"),s={};let c=!1;if(l.forEach((e=>{const t=e.attributes,n=g(t,u);let a=o?g(t,o):p(t,u);null===a&&0===n&&(c=!0),(null==a||"string"==typeof a&&""===a.trim())&&(a=null),null==s[a]?s[a]={count:n,data:a}:s[a].count=s[a].count+n})),o&&c){const e=o+" is NULL";return t.queryFeatureCount({whereClause:e,view:a,signal:r}).then((e=>(e=e||0,s.null.count=s.null.count+e,h(s,i)))).catch((()=>(n.throwIfAborted(r),h(s,i))))}return Promise.resolve(h(s,i))}function h(e,t){if(t)for(const n in e)e[n].label=t[n];return{count:e}}function x(e,t){return a.getDateDiffSQL(e,new Date(0),t,"milliseconds").sqlExpression}function y(e){var t;return{viewingMode:"2d"===e.type?"map":e.viewingMode,scale:e.scale,spatialReference:null==(t=e.spatialReference)?void 0:t.toJSON()}}function w(e,t){const n=e.map((e=>e.value)),a=t.filter((e=>!n.includes(e)));for(const o of a)e.push({value:o,count:0});e.sort(((e,n)=>t.indexOf(e.value)-t.indexOf(n.value)));for(const i of e)i.value===o.noDominantCategoryField&&(i.value=null);return{predominantCategoryInfos:e}}e.ensureFeaturesJSON=u,e.generateBinParams=m,e.getFieldExpr=d,e.getHistogramFromFeatureSet=F,e.getMissingFields=s,e.getPredominantCategoriesFromUVInfos=w,e.getSummaryStatisticsFromFeatureSet=f,e.getUniqueValuesFromFeatureSet=v,e.getViewInfoParams=y,e.msSinceUnixEpochSQL=x,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
