/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["exports"],(function(e){"use strict";function l(e,l){return Number(e.toFixed(l))}function t(e){const l=s(e),t=[],n=l.uniqueValues.length;for(let a=0;a<n;a++){const e=l.uniqueValues[a],n=l.valueFrequency[a],u=e.toString();t.push({value:e,count:n,label:u})}return{uniqueValues:t}}function n(e){const{normalizationTotal:l}=e;return{classBreaks:a(e),normalizationTotal:l}}function a(e){const t=e.definition,{classificationMethod:n,breakCount:a,normalizationType:r,definedInterval:i}=t,m=[];let b=e.values;if(0===b.length)return[];b=b.sort(((e,l)=>e-l));const V=b[0],p=b[b.length-1];if("equal-interval"===n)if(b.length>=a){const e=(p-V)/a;let t=V;for(let n=1;n<a;n++){const a=l(V+n*e,6);m.push({minValue:t,maxValue:a,label:u(t,a,r)}),t=a}m.push({minValue:t,maxValue:p,label:u(t,p,r)})}else b.forEach((e=>{m.push({minValue:e,maxValue:e,label:u(e,e,r)})}));else if("natural-breaks"===n){const t=s(b),n=e.valueFrequency||t.valueFrequency,i=o(t.uniqueValues,n,a);let c=V;for(let e=1;e<a;e++)if(t.uniqueValues.length>e){const n=l(t.uniqueValues[i[e]],6);m.push({minValue:c,maxValue:n,label:u(c,n,r)}),c=n}m.push({minValue:c,maxValue:p,label:u(c,p,r)})}else if("quantile"===n)if(b.length>=a&&V!==p){let e=V,l=Math.ceil(b.length/a),t=0;for(let n=1;n<a;n++){let s=l+t-1;s>b.length&&(s=b.length-1),s<0&&(s=0),m.push({minValue:e,maxValue:b[s],label:u(e,b[s],r)}),e=b[s],t+=l,l=Math.ceil((b.length-t)/(a-n))}m.push({minValue:e,maxValue:p,label:u(e,p,r)})}else{let e=-1;for(let l=0;l<b.length;l++){const t=b[l];t!==e&&(e=t,m.push({minValue:e,maxValue:t,label:u(e,t,r)}),e=t)}}else if("standard-deviation"===n){const e=f(b),t=h(b,e);if(0===t)m.push({minValue:b[0],maxValue:b[0],label:u(b[0],b[0],r)});else{const n=c(V,p,a,e,t)*t;let s=0,o=V;for(let t=a;t>=1;t--){const a=l(e-(t-.5)*n,6);m.push({minValue:o,maxValue:a,label:u(o,a,r)}),o=a,s++}let i=l(e+.5*n,6);m.push({minValue:o,maxValue:i,label:u(o,i,r)}),o=i,s++;for(let t=1;t<=a;t++)i=s===2*a?p:l(e+(t+.5)*n,6),m.push({minValue:o,maxValue:i,label:u(o,i,r)}),o=i,s++}}else if("defined-interval"===n){if(!i)return m;const e=b[0],t=b[b.length-1],n=Math.ceil((t-e)/i);let a=e;for(let s=1;s<n;s++){const t=l(e+s*i,6);m.push({minValue:a,maxValue:t,label:u(a,t,r)}),a=t}m.push({minValue:a,maxValue:t,label:u(a,t,r)})}return m}function u(e,l,t){let n=null;return n=e===l?t&&"percent-of-total"===t?e+"%":e.toString():t&&"percent-of-total"===t?e+"% - "+l+"%":e+" - "+l,n}function s(e){const l=[],t=[];let n=Number.MIN_VALUE,a=1,u=-1;for(let s=0;s<e.length;s++){const o=e[s];o===n?(a++,t[u]=a):null!==o&&(l.push(o),n=o,a=1,t.push(a),u++)}return{uniqueValues:l,valueFrequency:t}}function o(e,l,t){const n=e.length,a=[];t>n&&(t=n);for(let s=0;s<t;s++)a.push(Math.round(s*n/t-1));a.push(n-1);let u=r(a,e,l,t);return i(u.mean,u.sdcm,a,e,l,t)&&(u=r(a,e,l,t)),a}function r(e,l,t,n){let a=[],u=[],s=[],o=0;const r=[],i=[];for(let b=0;b<n;b++){const n=m(b,e,l,t);r.push(n.sbMean),i.push(n.sbSdcm),o+=i[b]}let c,f=o,h=!0;for(;h||o<f;){h=!1,a=[];for(let l=0;l<n;l++)a.push(e[l]);for(let t=0;t<n;t++)for(let a=e[t]+1;a<=e[t+1];a++)if(c=l[a],t>0&&a!==e[t+1]&&Math.abs(c-r[t])>Math.abs(c-r[t-1]))e[t]=a;else if(t<n-1&&e[t]!==a-1&&Math.abs(c-r[t])>Math.abs(c-r[t+1])){e[t+1]=a-1;break}f=o,o=0,u=[],s=[];for(let a=0;a<n;a++){u.push(r[a]),s.push(i[a]);const n=m(a,e,l,t);r[a]=n.sbMean,i[a]=n.sbSdcm,o+=i[a]}}if(o>f){for(let l=0;l<n;l++)e[l]=a[l],r[l]=u[l],i[l]=s[l];o=f}return{mean:r,sdcm:i}}function i(e,l,t,n,a,u){let s=0,o=0,r=0,i=0,c=!0;for(let f=0;f<2&&c;f++){0===f&&(c=!1);for(let f=0;f<u-1;f++)for(;t[f+1]+1!==t[f+2];){t[f+1]=t[f+1]+1;const u=m(f,t,n,a);r=u.sbMean,s=u.sbSdcm;const h=m(f+1,t,n,a);if(i=h.sbMean,o=h.sbSdcm,!(s+o<l[f]+l[f+1])){t[f+1]=t[f+1]-1;break}l[f]=s,l[f+1]=o,e[f]=r,e[f+1]=i,c=!0}for(let f=u-1;f>0;f--)for(;t[f]!==t[f-1]+1;){t[f]=t[f]-1;const u=m(f-1,t,n,a);r=u.sbMean,s=u.sbSdcm;const h=m(f,t,n,a);if(i=h.sbMean,o=h.sbSdcm,!(s+o<l[f-1]+l[f])){t[f]=t[f]+1;break}l[f-1]=s,l[f]=o,e[f-1]=r,e[f]=i,c=!0}}return c}function c(e,l,t,n,a){let u=Math.max(n-e,l-n)/a/t;return u=u>=1?1:u>=.5?.5:.25,u}function f(e){let l=0;for(let t=0;t<e.length;t++)l+=e[t];return l/=e.length,l}function h(e,l){let t=0;for(let n=0;n<e.length;n++){const a=e[n];t+=(a-l)*(a-l)}t/=e.length;return Math.sqrt(t)}function m(e,l,t,n){let a=0,u=0;for(let r=l[e]+1;r<=l[e+1];r++){const e=n[r];a+=t[r]*e,u+=e}u<=0&&console.log("Exception in Natural Breaks calculation");const s=a/u;let o=0;for(let r=l[e]+1;r<=l[e+1];r++)o+=n[r]*(t[r]-s)**2;return{sbMean:s,sbSdcm:o}}e.createGenerateRendererClassBreaks=n,e.createGenerateRendererUniqueValues=t,Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
