// lib/progress.ts
let active = 0;
let onChange: ((loading: boolean) => void) | null = null;

export const progress = {
  subscribe(cb: (loading: boolean) => void) {
    onChange = cb;
  },
  start() {
    active++;
    onChange?.(true);
  },
  finish() {
    active = Math.max(active - 1, 0);
    if (active === 0) onChange?.(false);
  },
};
