import k, { createContext as tt, useEffect as et, useLayoutEffect as nt } from "react";
import { FOCUS_EVENT as ot, RECONNECT_EVENT as st, MUTATE_EVENT as it } from "./events.js";
import { dequal as ct } from "../../../../../dequal@2.0.3/node_modules/dequal/lite/index.js";
const v = /* @__PURE__ */ new WeakMap(), C = () => {
}, u = (
  /*#__NOINLINE__*/
  C()
), F = Object, m = (t) => t === u, R = (t) => typeof t == "function", T = (t, e) => ({
  ...t,
  ...e
}), rt = (t) => R(t.then), g = {}, D = {}, U = "undefined", S = typeof window != U, j = typeof document != U, at = S && "Deno" in window, ut = () => S && typeof window.requestAnimationFrame != U, ft = (t, e) => {
  const o = v.get(t);
  return [
    // Getter
    () => !m(e) && t.get(e) || g,
    // Setter
    (c) => {
      if (!m(e)) {
        const i = t.get(e);
        e in D || (D[e] = i), o[5](e, T(i, c), i || g);
      }
    },
    // Subscriber
    o[6],
    // Get server cache snapshot
    () => !m(e) && e in D ? D[e] : !m(e) && t.get(e) || g
  ];
};
let x = !0;
const lt = () => x, [M, V] = S && window.addEventListener ? [
  window.addEventListener.bind(window),
  window.removeEventListener.bind(window)
] : [
  C,
  C
], dt = () => {
  const t = j && document.visibilityState;
  return m(t) || t !== "hidden";
}, mt = (t) => (j && document.addEventListener("visibilitychange", t), M("focus", t), () => {
  j && document.removeEventListener("visibilitychange", t), V("focus", t);
}), Et = (t) => {
  const e = () => {
    x = !0, t();
  }, o = () => {
    x = !1;
  };
  return M("online", e), M("offline", o), () => {
    V("online", e), V("offline", o);
  };
}, pt = {
  isOnline: lt,
  isVisible: dt
}, bt = {
  initFocus: mt,
  initReconnect: Et
}, gt = !k.useId, W = !S || at, Lt = (t) => ut() ? window.requestAnimationFrame(t) : setTimeout(t, 1), Nt = W ? et : nt, L = typeof navigator < "u" && navigator.connection, z = !W && L && ([
  "slow-2g",
  "2g"
].includes(L.effectiveType) || L.saveData), A = /* @__PURE__ */ new WeakMap(), N = (t, e) => F.prototype.toString.call(t) === `[object ${e}]`;
let ht = 0;
const P = (t) => {
  const e = typeof t, o = N(t, "Date"), c = N(t, "RegExp"), i = N(t, "Object");
  let n, s;
  if (F(t) === t && !o && !c) {
    if (n = A.get(t), n) return n;
    if (n = ++ht + "~", A.set(t, n), Array.isArray(t)) {
      for (n = "@", s = 0; s < t.length; s++)
        n += P(t[s]) + ",";
      A.set(t, n);
    }
    if (i) {
      n = "#";
      const E = F.keys(t).sort();
      for (; !m(s = E.pop()); )
        m(t[s]) || (n += s + ":" + P(t[s]) + ",");
      A.set(t, n);
    }
  } else
    n = o ? t.toJSON() : e == "symbol" ? t.toString() : e == "string" ? JSON.stringify(t) : "" + t;
  return n;
}, Ot = (t) => {
  if (R(t))
    try {
      t = t();
    } catch {
      t = "";
    }
  const e = t;
  return t = typeof t == "string" ? t : (Array.isArray(t) ? t.length : t) ? P(t) : "", [
    t,
    e
  ];
};
let wt = 0;
const G = () => ++wt;
async function Ct(...t) {
  const [e, o, c, i] = t, n = T({
    populateCache: !0,
    throwOnError: !0
  }, typeof i == "boolean" ? {
    revalidate: i
  } : i || {});
  let s = n.populateCache;
  const E = n.rollbackOnError;
  let O = n.optimisticData;
  const _ = (a) => typeof E == "function" ? E(a) : E !== !1, d = n.throwOnError;
  if (R(o)) {
    const a = o, r = [], w = e.keys();
    for (const p of w)
      // Skip the special useSWRInfinite and useSWRSubscription keys.
      !/^\$(inf|sub)\$/.test(p) && a(e.get(p)._k) && r.push(p);
    return Promise.all(r.map(f));
  }
  return f(o);
  async function f(a) {
    const [r] = Ot(a);
    if (!r) return;
    const [w, p] = ft(e, r), [Q, I, X, Z] = v.get(e), q = () => {
      const h = Q[r];
      return (R(n.revalidate) ? n.revalidate(w().data, a) : n.revalidate !== !1) && (delete X[r], delete Z[r], h && h[0]) ? h[0](it).then(() => w().data) : w().data;
    };
    if (t.length < 3)
      return q();
    let l = c, b;
    const H = G();
    I[r] = [
      H,
      0
    ];
    const B = !m(O), J = w(), K = J.data, $ = J._c, y = m($) ? K : $;
    if (B && (O = R(O) ? O(y, K) : O, p({
      data: O,
      _c: y
    })), R(l))
      try {
        l = l(y);
      } catch (h) {
        b = h;
      }
    if (l && rt(l))
      if (l = await l.catch((h) => {
        b = h;
      }), H !== I[r][0]) {
        if (b) throw b;
        return l;
      } else b && B && _(b) && (s = !0, p({
        data: y,
        _c: u
      }));
    if (s && !b)
      if (R(s)) {
        const h = s(l, y);
        p({
          data: h,
          error: u,
          _c: u
        });
      } else
        p({
          data: l,
          error: u,
          _c: u
        });
    if (I[r][1] = G(), Promise.resolve(q()).then(() => {
      p({
        _c: u
      });
    }), b) {
      if (d) throw b;
      return;
    }
    return l;
  }
}
const Y = (t, e) => {
  for (const o in t)
    t[o][0] && t[o][0](e);
}, vt = (t, e) => {
  if (!v.has(t)) {
    const o = T(bt, e), c = /* @__PURE__ */ Object.create(null), i = Ct.bind(u, t);
    let n = C;
    const s = /* @__PURE__ */ Object.create(null), E = (d, f) => {
      const a = s[d] || [];
      return s[d] = a, a.push(f), () => a.splice(a.indexOf(f), 1);
    }, O = (d, f, a) => {
      t.set(d, f);
      const r = s[d];
      if (r)
        for (const w of r)
          w(f, a);
    }, _ = () => {
      if (!v.has(t) && (v.set(t, [
        c,
        /* @__PURE__ */ Object.create(null),
        /* @__PURE__ */ Object.create(null),
        /* @__PURE__ */ Object.create(null),
        i,
        O,
        E
      ]), !W)) {
        const d = o.initFocus(setTimeout.bind(u, Y.bind(u, c, ot))), f = o.initReconnect(setTimeout.bind(u, Y.bind(u, c, st)));
        n = () => {
          d && d(), f && f(), v.delete(t);
        };
      }
    };
    return _(), [
      t,
      i,
      _,
      n
    ];
  }
  return [
    t,
    v.get(t)[4]
  ];
}, Rt = (t, e, o, c, i) => {
  const n = o.errorRetryCount, s = i.retryCount, E = ~~((Math.random() + 0.5) * (1 << (s < 8 ? s : 8))) * o.errorRetryInterval;
  !m(n) && s > n || setTimeout(c, E, i);
}, Tt = ct, [yt, _t] = vt(/* @__PURE__ */ new Map()), Ft = T(
  {
    // events
    onLoadingSlow: C,
    onSuccess: C,
    onError: C,
    onErrorRetry: Rt,
    onDiscarded: C,
    // switches
    revalidateOnFocus: !0,
    revalidateOnReconnect: !0,
    revalidateIfStale: !0,
    shouldRetryOnError: !0,
    // timeouts
    errorRetryInterval: z ? 1e4 : 5e3,
    focusThrottleInterval: 5 * 1e3,
    dedupingInterval: 2 * 1e3,
    loadingTimeout: z ? 5e3 : 3e3,
    // providers
    compare: Tt,
    isPaused: () => !1,
    cache: yt,
    mutate: _t,
    fallback: {}
  },
  // use web preset by default
  pt
), jt = (t, e) => {
  const o = T(t, e);
  if (e) {
    const { use: c, fallback: i } = t, { use: n, fallback: s } = e;
    c && n && (o.use = c.concat(n)), i && s && (o.fallback = T(i, s));
  }
  return o;
}, xt = tt({});
export {
  C as A,
  rt as B,
  gt as I,
  F as O,
  xt as S,
  u as U,
  R as a,
  v as b,
  yt as c,
  Ft as d,
  m as e,
  jt as f,
  vt as h,
  S as i,
  _t as j,
  Tt as k,
  P as l,
  T as m,
  Ct as n,
  G as o,
  pt as p,
  bt as q,
  W as r,
  Ot as s,
  Lt as t,
  Nt as u,
  z as v,
  j as w,
  at as x,
  ut as y,
  ft as z
};
//# sourceMappingURL=config-context-client-v7VOFo66.js.map
