/* COPYRIGHT Esri - https://js.arcgis.com/5.1.2/LICENSE.txt */
function t(t,e){return t===e?0:null===t?-1:null===e?1:t<e?-1:1}class e{constructor(t){const e=t.split(",");this._fields=[],this._directions=[];for(let s=0;s<e.length;s++){const t=e[s].match(/\S+/g);this._fields.push(t[0]),2===t.length?"asc"===t[1].toLowerCase()?this._directions.push(1):this._directions.push(0):this._directions.push(1)}}toOrderByFields(){return this._fields.map((t,e)=>t+(1===this._directions[e]?" ASC":" DESC"))}order(t){t.sort(this.toComparator())}toComparator(){return(e,s)=>{for(let i=0;i<this._fields.length;i++){const r=this.featureValue(e,this._fields[i],i),o=this.featureValue(s,this._fields[i],i);let l=0;if(l=1===this._directions[i]?t(r,o):-1*t(r,o),0!==l)return l}return 0}}scanForField(t){for(let e=0;e<this._fields.length;e++)if(this._fields[e].toLowerCase().trim()===t.toLowerCase().trim())return!0;return!1}replaceFields(t){let s="";for(let e=0;e<this._fields.length;e++){0!==e&&(s+=",");let i=this._fields[e];for(const e of t)if(i.toLowerCase()===e.field.toLowerCase()){i=e.newfield;break}s+=i,1===this._directions[e]?s+=" ASC":s+=" DESC"}return new e(s)}featureValue(t,e,s){const i=t.attributes[e];if(void 0!==i)return i;for(const r in t.attributes)if(e.toLowerCase()===r.toLowerCase())return this._fields[s]=r,t.attributes[r];return null}}export{e as default};
