import { s as __toESM } from "./chunk-BNovOVIE.js";
import { t as require_react } from "./react-DA-nE2FX.js";
import { t as require_compiler_runtime } from "./compiler-runtime-CEbnTgxf.js";
import { w as useEvent_default } from "./useTheme-DykuNHR2.js";
import { t as invariant } from "./invariant-UcGKQEhF.js";
var import_compiler_runtime = require_compiler_runtime(), import_react = /* @__PURE__ */ __toESM(require_react(), 1), Result = {
  error(e, s) {
    return {
      status: "error",
      data: s,
      error: e,
      isPending: false,
      isFetching: false
    };
  },
  success(e) {
    return {
      status: "success",
      data: e,
      error: void 0,
      isPending: false,
      isFetching: false
    };
  },
  loading(e) {
    return {
      status: "loading",
      data: e,
      error: void 0,
      isPending: false,
      isFetching: true
    };
  },
  pending() {
    return {
      status: "pending",
      data: void 0,
      error: void 0,
      isPending: true,
      isFetching: true
    };
  }
};
function useAsyncData(e, s) {
  let c = (0, import_compiler_runtime.c)(17), [l, u] = (0, import_react.useState)(0), d;
  c[0] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (d = Result.pending(), c[0] = d) : d = c[0];
  let [f, p] = (0, import_react.useState)(d), m;
  c[1] === e ? m = c[2] : (m = typeof e == "function" ? { fetch: e } : e, c[1] = e, c[2] = m);
  let h = useEvent_default(m.fetch), g;
  c[3] === h ? g = c[4] : (g = () => {
    let e2 = new AbortController(), s2 = false;
    return p(_temp), h({ previous: () => {
      s2 = true;
    } }).then((c2) => {
      e2.signal.aborted || s2 || p(Result.success(c2));
    }).catch((s3) => {
      e2.signal.aborted || p((e3) => Result.error(s3, e3.data));
    }), () => {
      e2.abort();
    };
  }, c[3] = h, c[4] = g);
  let _;
  c[5] !== s || c[6] !== h || c[7] !== l ? (_ = [
    ...s,
    l,
    h
  ], c[5] = s, c[6] = h, c[7] = l, c[8] = _) : _ = c[8], (0, import_react.useEffect)(g, _);
  let v;
  c[9] === f ? v = c[10] : (v = (e2) => {
    let s2;
    typeof e2 == "function" ? (invariant(f.status === "success" || f.status === "loading", "No previous state value."), s2 = e2(f.data)) : s2 = e2, p(Result.success(s2));
  }, c[9] = f, c[10] = v);
  let y;
  c[11] === l ? y = c[12] : (y = () => u(l + 1), c[11] = l, c[12] = y);
  let b;
  return c[13] !== f || c[14] !== v || c[15] !== y ? (b = {
    ...f,
    setData: v,
    refetch: y
  }, c[13] = f, c[14] = v, c[15] = y, c[16] = b) : b = c[16], b;
}
function _temp(e) {
  return e.status === "success" || e.status === "loading" ? Result.loading(e.data) : Result.pending();
}
export {
  useAsyncData as t
};
