import { ref as d, reactive as f, computed as h, unref as i, watch as m } from "vue";
import { exclusiveRequest as p, delay as y } from "@milaboratories/helpers";
function n(c, l, e) {
  const r = d(0), a = f({
    loading: h(() => r.value > 0),
    loadingRef: r,
    value: void 0,
    error: void 0
  }), v = p(async (o) => (e != null && e.debounce && await y(i(e.debounce)), l(o)));
  return m(
    c,
    async (o) => {
      e != null && e.filterWatchResult && !e.filterWatchResult(o) || (a.error = void 0, r.value++, v(o).then((u) => {
        u.ok && (a.value = u.value);
      }).catch((u) => {
        a.value = void 0, a.error = u;
      }).finally(() => {
        r.value--;
      }));
    },
    Object.assign({ immediate: !0, deep: !0 }, (e == null ? void 0 : e.watchOptions) ?? {})
  ), a;
}
export {
  n as useWatchFetch
};
//# sourceMappingURL=useWatchFetch.js.map
