/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["../../chunks/_rollupPluginBabelHelpers","../../core/Error","../../core/maybe","../../layers/support/fieldUtils","./support/utils","../support/utils","../support/adapters/support/layerUtils"],(function(e,i,r,a,s,t,o){"use strict";const n=["date",...a.numericTypes];function l(e){return p.apply(this,arguments)}function p(){return(p=e._asyncToGenerator((function*(e){if(!(e&&e.layer&&(e.field||e.valueExpression||e.sqlExpression)))throw new i("histogram:missing-parameters","'layer' and 'field', 'valueExpression' or 'sqlExpression' parameters are required");if(e.valueExpression&&!e.sqlExpression&&!e.view)throw new i("histogram:missing-parameters","View is required when 'valueExpression' is specified");const{layer:l,...p}=e,d=o.createLayerAdapter(l,o.defaultSupportedLayerTypes),u={layerAdapter:d,...p};if(u.normalizationType=t.getNormalizationType(u),!d)throw new i("histogram:invalid-parameters","'layer' must be one of these types: "+o.getLayerTypeLabels(o.defaultSupportedLayerTypes).join(", "));const f=r.isSome(u.signal)?{signal:u.signal}:null;yield d.load(f);const h=u.valueExpression||u.sqlExpression,y=u.field,m=y?d.getField(y):null,c=!u.classificationMethod||"equal-interval"===u.classificationMethod,w=yield t.getFieldsList({field:y,normalizationField:u.normalizationField,valueExpression:u.valueExpression}),v=s.verifyBasicFieldValidity(d,w,"histogram:invalid-parameters");if(v)throw v;if(m){const e=s.verifyFieldType(d,m,"histogram:invalid-parameters",n);if(e)throw e;if(a.isDateField(m)){if(u.normalizationType)throw new i("histogram:invalid-parameters","Normalization is not allowed for date fields");if(!c)throw new i("histogram:invalid-parameters","'classificationMethod' other than 'equal-interval' is not allowed for date fields")}}else if(h){if(u.normalizationType)throw new i("histogram:invalid-parameters","Normalization is not allowed when 'valueExpression' or 'sqlExpression' is specified");if(!c)throw new i("histogram:invalid-parameters","'classificationMethod' other than 'equal-interval' is not allowed when 'valueExpression' or 'sqlExpression' is specified")}return u}))).apply(this,arguments)}function d(e){return u.apply(this,arguments)}function u(){return(u=e._asyncToGenerator((function*(e){const{layerAdapter:i,...r}=yield l(e);return i.histogram(r)}))).apply(this,arguments)}return d}));
