import { b as e } from "./common-64096f9e.js";
import { ce as n, cf as t, cg as o, ch as r, ci as s, cj as a, ck as i, cl as c, cm as u, cn as d, co as l, cp as f, cq as w } from "./vendor-208d0ff5.js";
var h = function() {
  if ("undefined" != typeof self)
    return self;
  if ("undefined" != typeof window)
    return window;
  if ("undefined" != typeof global)
    return global;
  throw new Error("unable to locate global object");
}();
const p = h.fetch, v = h.fetch.bind(h), y = h.Headers, _ = h.Request, g = h.Response, b = Object.freeze(Object.defineProperty({ __proto__: null, Headers: y, Request: _, Response: g, default: v, fetch: p }, Symbol.toStringTag, { value: "Module" })), j = e(b);
var k = globalThis && globalThis.__awaiter || function(e2, n2, t2, o2) {
  return new (t2 || (t2 = Promise))(function(r2, s2) {
    function a2(e3) {
      try {
        c2(o2.next(e3));
      } catch (e4) {
        s2(e4);
      }
    }
    function i2(e3) {
      try {
        c2(o2.throw(e3));
      } catch (e4) {
        s2(e4);
      }
    }
    function c2(e3) {
      var n3;
      e3.done ? r2(e3.value) : (n3 = e3.value, n3 instanceof t2 ? n3 : new t2(function(e4) {
        e4(n3);
      })).then(a2, i2);
    }
    c2((o2 = o2.apply(e2, n2 || [])).next());
  });
};
const m = (e2) => e2.msg || e2.message || e2.error_description || e2.error || JSON.stringify(e2), O = (e2, r2, s2) => k(void 0, void 0, void 0, function* () {
  const a2 = yield n();
  e2 instanceof a2 && !(null == s2 ? void 0 : s2.noResolveJson) ? e2.json().then((n2) => {
    r2(new t(m(n2), e2.status || 500));
  }).catch((e3) => {
    r2(new o(m(e3), e3));
  }) : r2(new o(m(e2), e2));
}), T = (e2, n2, t2, o2) => {
  const r2 = { method: e2, headers: (null == n2 ? void 0 : n2.headers) || {} };
  return "GET" === e2 ? r2 : (r2.headers = Object.assign({ "Content-Type": "application/json" }, null == n2 ? void 0 : n2.headers), o2 && (r2.body = JSON.stringify(o2)), Object.assign(Object.assign({}, r2), t2));
};
function x(e2, n2, t2, o2, r2, s2) {
  return k(this, void 0, void 0, function* () {
    return new Promise((a2, i2) => {
      e2(t2, T(n2, o2, r2, s2)).then((e3) => {
        if (!e3.ok)
          throw e3;
        return (null == o2 ? void 0 : o2.noResolveJson) ? e3 : e3.json();
      }).then((e3) => a2(e3)).catch((e3) => O(e3, i2, o2));
    });
  });
}
function R(e2, n2, t2, o2) {
  return k(this, void 0, void 0, function* () {
    return x(e2, "GET", n2, t2, o2);
  });
}
function S(e2, n2, t2, o2, r2) {
  return k(this, void 0, void 0, function* () {
    return x(e2, "POST", n2, o2, r2, t2);
  });
}
function J(e2, n2, t2, o2, r2) {
  return k(this, void 0, void 0, function* () {
    return x(e2, "PUT", n2, o2, r2, t2);
  });
}
function P(e2, n2, t2, o2) {
  return k(this, void 0, void 0, function* () {
    return x(e2, "HEAD", n2, Object.assign(Object.assign({}, t2), { noResolveJson: true }), o2);
  });
}
function E(e2, n2, t2, o2, r2) {
  return k(this, void 0, void 0, function* () {
    return x(e2, "DELETE", n2, o2, r2, t2);
  });
}
var A = globalThis && globalThis.__awaiter || function(e2, n2, t2, o2) {
  return new (t2 || (t2 = Promise))(function(r2, s2) {
    function a2(e3) {
      try {
        c2(o2.next(e3));
      } catch (e4) {
        s2(e4);
      }
    }
    function i2(e3) {
      try {
        c2(o2.throw(e3));
      } catch (e4) {
        s2(e4);
      }
    }
    function c2(e3) {
      var n3;
      e3.done ? r2(e3.value) : (n3 = e3.value, n3 instanceof t2 ? n3 : new t2(function(e4) {
        e4(n3);
      })).then(a2, i2);
    }
    c2((o2 = o2.apply(e2, n2 || [])).next());
  });
};
const H = (e2) => {
  let n2;
  return n2 = e2 || ("undefined" == typeof fetch ? v : fetch), (...e3) => n2(...e3);
}, q = (e2, n2, t2) => {
  const o2 = H(t2), r2 = "undefined" == typeof Headers ? y : Headers;
  return (t3, s2) => A(void 0, void 0, void 0, function* () {
    var a2;
    const i2 = null !== (a2 = yield n2()) && void 0 !== a2 ? a2 : e2;
    let c2 = new r2(null == s2 ? void 0 : s2.headers);
    return c2.has("apikey") || c2.set("apikey", e2), c2.has("Authorization") || c2.set("Authorization", `Bearer ${i2}`), o2(t3, Object.assign(Object.assign({}, s2), { headers: c2 }));
  });
};
var z = globalThis && globalThis.__rest || function(e2, n2) {
  var t2 = {};
  for (var o2 in e2)
    Object.prototype.hasOwnProperty.call(e2, o2) && n2.indexOf(o2) < 0 && (t2[o2] = e2[o2]);
  if (null != e2 && "function" == typeof Object.getOwnPropertySymbols) {
    var r2 = 0;
    for (o2 = Object.getOwnPropertySymbols(e2); r2 < o2.length; r2++)
      n2.indexOf(o2[r2]) < 0 && Object.prototype.propertyIsEnumerable.call(e2, o2[r2]) && (t2[o2[r2]] = e2[o2[r2]]);
  }
  return t2;
};
const N = (e2) => e2.msg || e2.message || e2.error_description || e2.error || JSON.stringify(e2), G = [502, 503, 504];
async function U(e2) {
  var n2;
  if (!c(e2))
    throw new a(N(e2), 0);
  if (G.includes(e2.status))
    throw new a(N(e2), e2.status);
  let t2, o2;
  try {
    t2 = await e2.json();
  } catch (e3) {
    throw new u(N(e3), e3);
  }
  const r2 = d(e2);
  if (r2 && r2.getTime() >= s["2024-01-01"].timestamp && "object" == typeof t2 && t2 && "string" == typeof t2.code ? o2 = t2.code : "object" == typeof t2 && t2 && "string" == typeof t2.error_code && (o2 = t2.error_code), o2) {
    if ("weak_password" === o2)
      throw new l(N(t2), e2.status, (null === (n2 = t2.weak_password) || void 0 === n2 ? void 0 : n2.reasons) || []);
    if ("session_not_found" === o2)
      throw new f();
  } else if ("object" == typeof t2 && t2 && "object" == typeof t2.weak_password && t2.weak_password && Array.isArray(t2.weak_password.reasons) && t2.weak_password.reasons.length && t2.weak_password.reasons.reduce((e3, n3) => e3 && "string" == typeof n3, true))
    throw new l(N(t2), e2.status, t2.weak_password.reasons);
  throw new w(N(t2), e2.status || 500, o2);
}
const B = (e2, n2, t2, o2) => {
  const r2 = { method: e2, headers: (null == n2 ? void 0 : n2.headers) || {} };
  return "GET" === e2 ? r2 : (r2.headers = Object.assign({ "Content-Type": "application/json;charset=UTF-8" }, null == n2 ? void 0 : n2.headers), r2.body = JSON.stringify(o2), Object.assign(Object.assign({}, r2), t2));
};
async function C(e2, n2, t2, o2) {
  var i2;
  const c2 = Object.assign({}, null == o2 ? void 0 : o2.headers);
  c2[r] || (c2[r] = s["2024-01-01"].name), (null == o2 ? void 0 : o2.jwt) && (c2.Authorization = `Bearer ${o2.jwt}`);
  const u2 = null !== (i2 = null == o2 ? void 0 : o2.query) && void 0 !== i2 ? i2 : {};
  (null == o2 ? void 0 : o2.redirectTo) && (u2.redirect_to = o2.redirectTo);
  const d2 = Object.keys(u2).length ? "?" + new URLSearchParams(u2).toString() : "", l2 = await async function(e3, n3, t3, o3, r2, s2) {
    const i3 = B(n3, o3, r2, s2);
    let c3;
    try {
      c3 = await e3(t3, Object.assign({}, i3));
    } catch (e4) {
      throw console.error(e4), new a(N(e4), 0);
    }
    c3.ok || await U(c3);
    if (null == o3 ? void 0 : o3.noResolveJson)
      return c3;
    try {
      return await c3.json();
    } catch (e4) {
      await U(e4);
    }
  }(e2, n2, t2 + d2, { headers: c2, noResolveJson: null == o2 ? void 0 : o2.noResolveJson }, {}, null == o2 ? void 0 : o2.body);
  return (null == o2 ? void 0 : o2.xform) ? null == o2 ? void 0 : o2.xform(l2) : { data: Object.assign({}, l2), error: null };
}
function D(e2) {
  var n2;
  let t2 = null;
  (function(e3) {
    return e3.access_token && e3.refresh_token && e3.expires_in;
  })(e2) && (t2 = Object.assign({}, e2), e2.expires_at || (t2.expires_at = i(e2.expires_in)));
  return { data: { session: t2, user: null !== (n2 = e2.user) && void 0 !== n2 ? n2 : e2 }, error: null };
}
function L(e2) {
  const n2 = D(e2);
  return !n2.error && e2.weak_password && "object" == typeof e2.weak_password && Array.isArray(e2.weak_password.reasons) && e2.weak_password.reasons.length && e2.weak_password.message && "string" == typeof e2.weak_password.message && e2.weak_password.reasons.reduce((e3, n3) => e3 && "string" == typeof n3, true) && (n2.data.weak_password = e2.weak_password), n2;
}
function $(e2) {
  var n2;
  return { data: { user: null !== (n2 = e2.user) && void 0 !== n2 ? n2 : e2 }, error: null };
}
function F(e2) {
  return { data: e2, error: null };
}
function I(e2) {
  const { action_link: n2, email_otp: t2, hashed_token: o2, redirect_to: r2, verification_type: s2 } = e2, a2 = z(e2, ["action_link", "email_otp", "hashed_token", "redirect_to", "verification_type"]);
  return { data: { properties: { action_link: n2, email_otp: t2, hashed_token: o2, redirect_to: r2, verification_type: s2 }, user: Object.assign({}, a2) }, error: null };
}
function M(e2) {
  return e2;
}
export {
  C as _,
  E as a,
  J as b,
  M as c,
  $ as d,
  I as e,
  D as f,
  R as g,
  P as h,
  F as i,
  L as j,
  q as k,
  b as l,
  S as p,
  j as r
};
