/*
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","../../../chunks/tslib.es6","../../../core/Error","../../../core/maybe","../../../core/Logger","../../../core/accessorSupport/ensureType","../../../core/arrayUtils","../../../core/has","../../../core/accessorSupport/set","../../../core/accessorSupport/decorators/subclass","../../../rest/support/generateRendererUtils","../../statistics/support/utils","../../statistics/support/WorkerClient","../utils","./FeatureLayerAdapter","./support/utils"],(function(e,t,r,n,i,s,a,o,l,u,c,p,d,f,y,h){"use strict";function m(e){return"esri.rest.support.ClassBreaksDefinition"===e.declaredClass}function g(e){return"esri.rest.support.UniqueValueDefinition"===e.declaredClass}let v=function(t){function i(e){return t.call(this,e)||this}e._inheritsLoose(i,t);var s=i.prototype;return s._createGenerateRendererResult=function(){var t=e._asyncToGenerator((function*(e,t,n,i,s){const a=null==e?void 0:e.features;if(!(null==a?void 0:a.length))throw new r("csv-layer-adapter:insufficient-data","No features are available to calculate statistics");const o=h.ensureFeaturesJSON(a);let l=null;if("percent-of-total"===i){if(l=(yield this.workerClient.summaryStatistics({field:t},o)).sum,null==l)throw new r("csv-layer-adapter:invalid","invalid normalizationTotal")}if(m(s)){const e=(yield p.getDataValues({field:t,normalizationType:i,normalizationField:n,normalizationTotal:l},o)).filter((e=>Number.isFinite(e)));return c.createGenerateRendererClassBreaks({definition:s,values:e,normalizationTotal:l})}if(g(s)){const e=(yield p.getDataValues({field:t},o)).filter((e=>null!=e&&"string"==typeof e&&""!==e.trim()));return c.createGenerateRendererUniqueValues(e)}}));function n(e,r,n,i,s){return t.apply(this,arguments)}return n}(),s.generateRenderer=function(e,t){const r=e.classificationDefinition;let n=null,i=null,s=null;m(r)?(n=r.classificationField,i=r.normalizationField,s=r.normalizationType):g(r)&&(n=r.attributeField);const a=this.layer;return f.getFieldsList({field:n,normalizationField:i}).then((o=>{const l=a.createQuery();return l.returnGeometry=!1,l.outFields=o,l.where=p.mergeWhereClauses(l.where,e.where),a.queryFeatures(l,{signal:t}).then((e=>this._createGenerateRendererResult(e,n,i,s,r)))}))},s.load=function(t){var r=this;const i=this.layer.load(t).then(function(){var i=e._asyncToGenerator((function*(e){r.geometryType=e.geometryType,r.objectIdField=e.objectIdField,r.supportsSQLExpression=!0,r._hasLocalSource=!1,r.hasQueryEngine=!0,r.workerClient=d.WorkerClient.getInstance(),yield r.workerClient.open(n.unwrap(n.unwrap(t).signal))}));return function(e){return i.apply(this,arguments)}}());return this.addResolvingPromise(i),Promise.resolve(this)},i}(y);v=t.__decorate([u.subclass("esri.smartMapping.support.adapters.CSVLayerAdapter")],v);return v}));
