/*
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"],(function(t){"use strict";let e=function(){function e(t,e){this._lastId=-1,this._progress=e,this._parent=t}var n=e.prototype;return n.reset=function(){this._lastId=-1},n.nextBatch=function(t){if(null!==this._parent._mainSetInUse)return this._parent._mainSetInUse.then((e=>this.nextBatch(t)),(e=>this.nextBatch(t)));const e={returnpromise:null,hasset:!1},n=[];return e.returnpromise=new Promise(((s,r)=>{this._parent._getSet(this._progress).then((i=>{let a=i._known.length-1;if("GETPAGES"===i._known[i._known.length-1]&&(a-=1),this._lastId+t>a&&i._known.length>0&&"GETPAGES"===i._known[i._known.length-1])this._parent._expandPagedSet(i,this._parent._maxQueryRate(),0,0,this._progress).then((n=>{e.hasset=!0,this._parent._mainSetInUse=null,this.nextBatch(t).then(s,r)}),(t=>{e.hasset=!0,this._parent._mainSetInUse=null,r(t)}));else{if(a>=this._lastId+t||0===i._candidates.length){for(let e=0;e<t;e++){const t=e+this._lastId+1;if(t>=i._known.length)break;n[e]=i._known[t]}return this._lastId+=n.length,0===n.length&&(e.hasset=!0,this._parent._mainSetInUse=null,s([])),void this._parent._getFeatureBatch(n,this._progress).then((t=>{e.hasset=!0,this._parent._mainSetInUse=null,s(t)}),(t=>{e.hasset=!0,this._parent._mainSetInUse=null,r(t)}))}this._parent._refineSetBlock(i,this._parent._maxProcessingRate(),this._progress).then((()=>{e.hasset=!0,this._parent._mainSetInUse=null,this.nextBatch(t).then(s,r)}),(t=>{e.hasset=!0,this._parent._mainSetInUse=null,r(t)}))}}),(t=>{e.hasset=!0,this._parent._mainSetInUse=null,r(t)}))})),!1===e.hasset&&(this._parent._mainSetInUse=e.returnpromise,e.hasset=!0),e.returnpromise},n.next=function(){if(null!==this._parent._mainSetInUse)return this._parent._mainSetInUse.then((t=>this.next()),(t=>this.next()));const t={returnpromise:null,hasset:!1};return t.returnpromise=new Promise(((e,n)=>{this._parent._getSet(this._progress).then((s=>{this._lastId<s._known.length-1?"GETPAGES"===s._known[this._lastId+1]?this._parent._expandPagedSet(s,this._parent._maxQueryRate(),0,0,this._progress).then((e=>(t.hasset=!0,this._parent._mainSetInUse=null,this.next()))).then(e,n):(this._lastId+=1,this._parent._getFeature(s,s._known[this._lastId],this._progress).then((n=>{t.hasset=!0,this._parent._mainSetInUse=null,e(n)}),(e=>{t.hasset=!0,this._parent._mainSetInUse=null,n(e)}))):s._candidates.length>0?this._parent._refineSetBlock(s,this._parent._maxProcessingRate(),this._progress).then((()=>{t.hasset=!0,this._parent._mainSetInUse=null,this.next().then(e,n)}),(e=>{t.hasset=!0,this._parent._mainSetInUse=null,n(e)})):(t.hasset=!0,this._parent._mainSetInUse=null,e(null))}),(e=>{t.hasset=!0,this._parent._mainSetInUse=null,n(e)}))})),!1===t.hasset&&(this._parent._mainSetInUse=t.returnpromise,t.hasset=!0),t.returnpromise},n.count=function(){var e=t._asyncToGenerator((function*(){if(-1!==this._parent._totalCount)return this._parent._totalCount;const t=yield this._parent._getSet(this._progress),e=yield this._refineAllSets(t);return this._parent._totalCount=e._known.length,this._parent._totalCount}));function n(){return e.apply(this,arguments)}return n}(),n._refineAllSets=function(){var e=t._asyncToGenerator((function*(t){if(t._known.length>0&&"GETPAGES"===t._known[t._known.length-1])return yield this._parent._expandPagedSet(t,this._parent._maxQueryRate(),0,1,this._progress),this._refineAllSets(t);if(t._candidates.length>0){if("GETPAGES"===t._known[t._candidates.length-1])return yield this._parent._expandPagedSet(t,this._parent._maxQueryRate(),0,2,this._progress),this._refineAllSets(t);const e=yield this._parent._refineSetBlock(t,this._parent._maxProcessingRate(),this._progress);return e._candidates.length>0?this._refineAllSets(e):e}return t}));function n(t){return e.apply(this,arguments)}return n}(),e}();return e}));
