class RequestListenerLoadingBar {
  constructor() {
    this._debounceTime = 1000;
    this._ignoredNameTypes = ["totals"];
    this._countRequest = 0;
  }
  onRequestStart(param) {
    if (this.isIgnoreLoadingOnRequest(param)) {
      return;
    }
    this._countRequest++;
    this.ezLoadingBar.show();
    if (this._timerLoading) {
      clearTimeout(this._timerLoading);
    }
  }
  ;
  onRequestEnd(param) {
    if (this.isIgnoreLoadingOnRequest(param)) {
      return;
    }
    this._countRequest--;
    this._timerLoading = setTimeout(() => {
      if (this._countRequest <= 0) {
        this.ezLoadingBar.hide();
      }
    }, this._debounceTime);
  }
  ;
  isIgnoreLoadingOnRequest(param) {
    if (param == undefined) {
      return false;
    }
    if (param.url.includes("quietMode=true")) {
      return true;
    }
    if (param.requestBody == undefined) {
      return false;
    }
    if (param.requestBody.length == 1) {
      const { name } = param.requestBody[0].variables;
      if (name) {
        const nameParts = name.split(":");
        const nameType = nameParts[0];
        return this._ignoredNameTypes.indexOf(nameType) >= 0;
      }
    }
    return false;
  }
  ;
}
export default RequestListenerLoadingBar;
