import { Injectable, signal, computed } from '@angular/core';

@Injectable({
  providedIn: 'root'
})
export class LoaderService {

  private _requestCount = signal(0);

  // computed loader state
  isLoading = computed(() => this._requestCount() > 0);

  increase() {
    this._requestCount.update(c => c + 1);
  }

  decrease() {
    this._requestCount.update(c => Math.max(0, c - 1));
  }

  reset() {
    this._requestCount.set(0);
  }
}
