/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
import{__decorate as t}from"tslib";import has from"../../../core/has.js";import{Loadable as e}from"../../../core/Loadable.js";import{debounce as o}from"../../../core/promiseUtils.js";import{open as i}from"../../../core/workers.js";import{property as r,subclass as n}from"../../../core/accessorSupport/decorators.js";import s from"../../../geometry/Extent.js";import a from"../../../rest/support/FeatureSet.js";let c=class extends e{constructor(t){super(t),this.type="csv",this.refresh=o(async t=>{await this.load();const{extent:e,timeExtent:o}=await this._connection.invoke("refresh",t);return e&&(this.sourceJSON.extent=e),o&&(this.sourceJSON.timeInfo.timeExtent=[o.start,o.end]),{dataChanged:!0,updates:{extent:this.sourceJSON.extent,timeInfo:this.sourceJSON.timeInfo}}})}load(t){const e=null!=t?t.signal:null;return this.addResolvingPromise(this._startWorker(e)),Promise.resolve(this)}destroy(){this._connection?.close(),this._connection=null}async openPorts(){return await this.load(),this._connection.openPorts()}async queryFeatures(t,e={}){await this.load(e);const o=await this._connection.invoke("queryFeatures",t?t.toJSON():null,e);return a.fromJSON(o)}async queryFeaturesJSON(t,e={}){return await this.load(e),this._connection.invoke("queryFeatures",t?t.toJSON():null,e)}async queryFeatureCount(t,e={}){return await this.load(e),this._connection.invoke("queryFeatureCount",t?t.toJSON():null,e)}async queryObjectIds(t,e={}){return await this.load(e),this._connection.invoke("queryObjectIds",t?t.toJSON():null,e)}async queryExtent(t,e={}){await this.load(e);const o=await this._connection.invoke("queryExtent",t?t.toJSON():null,e);return{count:o.count,extent:s.fromJSON(o.extent)}}async querySnapping(t,e={}){return await this.load(e),this._connection.invoke("querySnapping",t,e)}async queryAttributeBins(t,e={}){return await this.load(),this._connection.invoke("queryAttributeBins",t?t.toJSON():null,e)}async _startWorker(t){this._connection=await i("CSVSourceWorker",{strategy:has("feature-layers-workers")?"dedicated":"local",signal:t,registryTarget:this});const{url:e,delimiter:o,fields:r,latitudeField:n,longitudeField:s,spatialReference:a,timeInfo:c}=this.loadOptions,u=await this._connection.invoke("load",{url:e,customParameters:this.customParameters,parsingOptions:{delimiter:o,fields:r?.map(t=>t.toJSON()),latitudeField:n,longitudeField:s,spatialReference:a?.toJSON(),timeInfo:c?.toJSON()}},{signal:t});this.locationInfo=u.locationInfo,this.sourceJSON=u.layerDefinition,this.delimiter=u.delimiter}};t([r()],c.prototype,"type",void 0),t([r()],c.prototype,"loadOptions",void 0),t([r()],c.prototype,"customParameters",void 0),t([r()],c.prototype,"locationInfo",void 0),t([r()],c.prototype,"sourceJSON",void 0),t([r()],c.prototype,"delimiter",void 0),c=t([n("esri.layers.graphics.sources.CSVSource")],c);export{c as CSVSource};
