/*
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/languageUtils","../support/FeatureSet","../support/IdSet","../support/OrderbyClause"],(function(e,t,n,r,i){"use strict";let s=function(s){function u(e){var t;return(t=s.call(this,e)||this)._orderbyclause=null,t.declaredClass="esri.arcade.featureset.actions.OrderBy",t._maxProcessing=100,t._orderbyclause=e.orderbyclause,t._parent=e.parentfeatureset,t}e._inheritsLoose(u,s);var a=u.prototype;return a._getSet=function(){var t=e._asyncToGenerator((function*(e){if(null===this._wset){yield this._ensureLoaded();const t=yield this._getFilteredSet("",null,null,this._orderbyclause,e);return this._checkCancelled(e),this._wset=t,this._wset}return this._wset}));function n(e){return t.apply(this,arguments)}return n}(),a.manualOrderSet=function(){var t=e._asyncToGenerator((function*(e,t){const n=yield this.getIdColumnDictionary(e,[],-1,t);this._orderbyclause.order(n);const i=new r([],[],!0,null);for(let r=0;r<n.length;r++)i._known.push(n[r].id);return i}));function n(e,n){return t.apply(this,arguments)}return n}(),a.getIdColumnDictionary=function(){var n=e._asyncToGenerator((function*(e,n,r,i){if(r<e._known.length-1){const s=this._maxQueryRate();if("GETPAGES"===e._known[r+1])return yield t.tick(this._parent._expandPagedSet(e,s,0,0,i)),this.getIdColumnDictionary(e,n,r,i);let u=r+1;const a=[];for(;u<e._known.length&&"GETPAGES"!==e._known[u];)a.push(e._known[u]),u++;r+=a.length;const o=yield t.tick(this._parent._getFeatureBatch(a,i));this._checkCancelled(i);for(const e of o)n.push({id:e.attributes[this.objectIdField],feature:e});return this.getIdColumnDictionary(e,n,r,i)}return e._candidates.length>0?(yield t.tick(this._refineSetBlock(e,this._maxProcessingRate(),i)),this._checkCancelled(i),this.getIdColumnDictionary(e,n,r,i)):n}));function r(e,t,r,i){return n.apply(this,arguments)}return r}(),a._isInFeatureSet=function(e){return this._parent._isInFeatureSet(e)},a._getFeatures=function(e,t,n,r){return this._parent._getFeatures(e,t,n,r)},a._featureFromCache=function(e){if(void 0===this._featureCache[e]){const t=this._parent._featureFromCache(e);if(void 0===t)return;return null===t?null:(this._featureCache[e]=t,t)}return this._featureCache[e]},a._fetchAndRefineFeatures=function(){var t=e._asyncToGenerator((function*(){throw new Error("Fetch and Refine should not be called in this featureset")}));function n(){return t.apply(this,arguments)}return n}(),a._getFilteredSet=function(){var t=e._asyncToGenerator((function*(e,t,n,i,s){yield this._ensureLoaded();const u=yield this._parent._getFilteredSet(e,t,n,null===i?this._orderbyclause:i,s);this._checkCancelled(s);const a=new r(u._candidates.slice(0),u._known.slice(0),u._ordered,this._clonePageDefinition(u.pagesDefinition));let o=!0;if(u._candidates.length>0&&(o=!1),!1===a._ordered){let e=yield this.manualOrderSet(a,s);return!1===o&&(null===t&&null===n||(e=new r(e._candidates.slice(0).concat(e._known.slice(0)),[],e._ordered,this._clonePageDefinition(e.pagesDefinition)))),e}return a}));function n(e,n,r,i,s){return t.apply(this,arguments)}return n}(),u.registerAction=function(){n._featuresetFunctions.orderBy=function(e){return""===e?this:new u({parentfeatureset:this,orderbyclause:new i(e)})}},u}(n);return s}));
