/*
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/asyncUtils","../../../../../core/maybe","../../../../../core/promiseUtils","../../../../../geometry/support/aaBoundingRect"],(function(t,e,a,s,r,n){"use strict";let T=function(){function T(e,a){this.data=e,this.resolution=a,this.state={type:t.StateType.CREATED},this.alive=!0}var u=T.prototype;return u.process=function(e){switch(this.state.type){case t.StateType.CREATED:return this.state=this._gotoFetchCount(this.state,e),this.state.task.promise.then(e.resume,e.resume);case t.StateType.FETCH_COUNT:break;case t.StateType.FETCHED_COUNT:return this.state=this._gotoFetchFeatures(this.state,e),this.state.task.promise.then(e.resume,e.resume);case t.StateType.FETCH_FEATURES:break;case t.StateType.FETCHED_FEATURES:this.state=this._goToDone(this.state,e);case t.StateType.DONE:}return null},u._gotoFetchCount=function(s,n){var T=this;return{type:t.StateType.FETCH_COUNT,previous:s,task:r.createTask(function(){var s=e._asyncToGenerator((function*(e){const s=yield a.resultOrAbort(n.fetchCount(T,e));T.state.type===t.StateType.FETCH_COUNT&&(T.state=T._gotoFetchedCount(T.state,s.ok?s.value:1/0))}));return function(t){return s.apply(this,arguments)}}())}},u._gotoFetchedCount=function(e,a){return{type:t.StateType.FETCHED_COUNT,featureCount:a,previous:e}},u._gotoFetchFeatures=function(s,n){var T=this;return{type:t.StateType.FETCH_FEATURES,previous:s,task:r.createTask(function(){var r=e._asyncToGenerator((function*(e){const r=yield a.resultOrAbort(n.fetchFeatures(T,s.featureCount,e));T.state.type===t.StateType.FETCH_FEATURES&&(T.state=T._gotoFetchedFeatures(T.state,r.ok?r.value:[]))}));return function(t){return r.apply(this,arguments)}}())}},u._gotoFetchedFeatures=function(e,a){return{type:t.StateType.FETCHED_FEATURES,previous:e,features:a}},u._goToDone=function(e,a){return a.finish(this,e.features),{type:t.StateType.DONE,previous:e}},u.reset=function(){const e=this.state;switch(this.state={type:t.StateType.CREATED},e.type){case t.StateType.CREATED:case t.StateType.FETCHED_COUNT:case t.StateType.FETCHED_FEATURES:case t.StateType.DONE:break;case t.StateType.FETCH_COUNT:case t.StateType.FETCH_FEATURES:e.task.abort()}},u.intersects=function(t){return!(!s.isNone(t)&&this.data.extent)||(n.fromExtent(t,o),n.intersects(this.data.extent,o))},e._createClass(T,[{key:"debugInfo",get:function(){return{data:this.data,featureCount:this.featureCount,state:this.stateToString}}},{key:"featureCount",get:function(){switch(this.state.type){case t.StateType.CREATED:case t.StateType.FETCH_COUNT:return 0;case t.StateType.FETCHED_COUNT:return this.state.featureCount;case t.StateType.FETCH_FEATURES:return this.state.previous.featureCount;case t.StateType.FETCHED_FEATURES:return this.state.features.length;case t.StateType.DONE:return this.state.previous.features.length}}},{key:"stateToString",get:function(){switch(this.state.type){case t.StateType.CREATED:return"created";case t.StateType.FETCH_COUNT:return"fetch-count";case t.StateType.FETCHED_COUNT:return"fetched-count";case t.StateType.FETCH_FEATURES:return"fetch-features";case t.StateType.FETCHED_FEATURES:return"fetched-features";case t.StateType.DONE:return"done"}}}]),T}();var u;t.StateType=void 0,(u=t.StateType||(t.StateType={}))[u.CREATED=0]="CREATED",u[u.FETCH_COUNT=1]="FETCH_COUNT",u[u.FETCHED_COUNT=2]="FETCHED_COUNT",u[u.FETCH_FEATURES=3]="FETCH_FEATURES",u[u.FETCHED_FEATURES=4]="FETCHED_FEATURES",u[u.DONE=5]="DONE";const o=n.create();t.PendingFeatureTile=T,Object.defineProperties(t,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
