import X from "./accelbyte-widgets568.mjs";
import ve from "./accelbyte-widgets569.mjs";
import k from "./accelbyte-widgets570.mjs";
import Q from "./accelbyte-widgets571.mjs";
function z(e) {
  return e.charAt(0) === "/" ? e : "/" + e;
}
function oe(e) {
  return e.charAt(0) === "/" ? e.substr(1) : e;
}
function ee(e, n) {
  return e.toLowerCase().indexOf(n.toLowerCase()) === 0 && "/?#".indexOf(e.charAt(n.length)) !== -1;
}
function fe(e, n) {
  return ee(e, n) ? e.substr(n.length) : e;
}
function de(e) {
  return e.charAt(e.length - 1) === "/" ? e.slice(0, -1) : e;
}
function pe(e) {
  var n = e || "/", d = "", f = "", o = n.indexOf("#");
  o !== -1 && (f = n.substr(o), n = n.substr(0, o));
  var p = n.indexOf("?");
  return p !== -1 && (d = n.substr(p), n = n.substr(0, p)), {
    pathname: n,
    search: d === "?" ? "" : d,
    hash: f === "#" ? "" : f
  };
}
function I(e) {
  var n = e.pathname, d = e.search, f = e.hash, o = n || "/";
  return d && d !== "?" && (o += d.charAt(0) === "?" ? d : "?" + d), f && f !== "#" && (o += f.charAt(0) === "#" ? f : "#" + f), o;
}
function U(e, n, d, f) {
  var o;
  typeof e == "string" ? (o = pe(e), o.state = n) : (o = X({}, e), o.pathname === void 0 && (o.pathname = ""), o.search ? o.search.charAt(0) !== "?" && (o.search = "?" + o.search) : o.search = "", o.hash ? o.hash.charAt(0) !== "#" && (o.hash = "#" + o.hash) : o.hash = "", n !== void 0 && o.state === void 0 && (o.state = n));
  try {
    o.pathname = decodeURI(o.pathname);
  } catch (p) {
    throw p instanceof URIError ? new URIError('Pathname "' + o.pathname + '" could not be decoded. This is likely caused by an invalid percent-encoding.') : p;
  }
  return d && (o.key = d), f ? o.pathname ? o.pathname.charAt(0) !== "/" && (o.pathname = ve(o.pathname, f.pathname)) : o.pathname = f.pathname : o.pathname || (o.pathname = "/"), o;
}
function ne() {
  var e = null;
  function n(g) {
    return process.env.NODE_ENV !== "production" && k(e == null, "A history supports only one prompt at a time"), e = g, function() {
      e === g && (e = null);
    };
  }
  function d(g, y, h, v) {
    if (e != null) {
      var m = typeof e == "function" ? e(g, y) : e;
      typeof m == "string" ? typeof h == "function" ? h(m, v) : (process.env.NODE_ENV !== "production" && k(!1, "A history needs a getUserConfirmation function in order to use a prompt message"), v(!0)) : v(m !== !1);
    } else
      v(!0);
  }
  var f = [];
  function o(g) {
    var y = !0;
    function h() {
      y && g.apply(void 0, arguments);
    }
    return f.push(h), function() {
      y = !1, f = f.filter(function(v) {
        return v !== h;
      });
    };
  }
  function p() {
    for (var g = arguments.length, y = new Array(g), h = 0; h < g; h++)
      y[h] = arguments[h];
    f.forEach(function(v) {
      return v.apply(void 0, y);
    });
  }
  return {
    setPrompt: n,
    confirmTransitionTo: d,
    appendListener: o,
    notifyListeners: p
  };
}
var he = !!(typeof window < "u" && window.document && window.document.createElement);
function ue(e, n) {
  n(window.confirm(e));
}
function ge() {
  var e = window.navigator.userAgent;
  return (e.indexOf("Android 2.") !== -1 || e.indexOf("Android 4.0") !== -1) && e.indexOf("Mobile Safari") !== -1 && e.indexOf("Chrome") === -1 && e.indexOf("Windows Phone") === -1 ? !1 : window.history && "pushState" in window.history;
}
function me() {
  return window.navigator.userAgent.indexOf("Trident") === -1;
}
function we() {
  return window.navigator.userAgent.indexOf("Firefox") === -1;
}
function ye(e) {
  return e.state === void 0 && navigator.userAgent.indexOf("CriOS") === -1;
}
var ie = "popstate", ae = "hashchange";
function re() {
  try {
    return window.history.state || {};
  } catch {
    return {};
  }
}
function ke(e) {
  e === void 0 && (e = {}), he || (process.env.NODE_ENV !== "production" ? Q(!1, "Browser history needs a DOM") : Q(!1));
  var n = window.history, d = ge(), f = !me(), o = e, p = o.forceRefresh, g = p === void 0 ? !1 : p, y = o.getUserConfirmation, h = y === void 0 ? ue : y, v = o.keyLength, m = v === void 0 ? 6 : v, H = e.basename ? de(z(e.basename)) : "";
  function M(a) {
    var s = a || {}, t = s.key, i = s.state, c = window.location, l = c.pathname, A = c.search, O = c.hash, w = l + A + O;
    return process.env.NODE_ENV !== "production" && k(!H || ee(w, H), 'You are attempting to use a basename on a page whose URL path does not begin with the basename. Expected path "' + w + '" to begin with "' + H + '".'), H && (w = fe(w, H)), U(w, i, t);
  }
  function N() {
    return Math.random().toString(36).substr(2, m);
  }
  var b = ne();
  function D(a) {
    X(_, a), _.length = n.length, b.notifyListeners(_.location, _.action);
  }
  function V(a) {
    ye(a) || F(M(a.state));
  }
  function B() {
    F(M(re()));
  }
  var R = !1;
  function F(a) {
    if (R)
      R = !1, D();
    else {
      var s = "POP";
      b.confirmTransitionTo(a, s, h, function(t) {
        t ? D({
          action: s,
          location: a
        }) : q(a);
      });
    }
  }
  function q(a) {
    var s = _.location, t = T.indexOf(s.key);
    t === -1 && (t = 0);
    var i = T.indexOf(a.key);
    i === -1 && (i = 0);
    var c = t - i;
    c && (R = !0, P(c));
  }
  var $ = M(re()), T = [$.key];
  function u(a) {
    return H + I(a);
  }
  function r(a, s) {
    process.env.NODE_ENV !== "production" && k(!(typeof a == "object" && a.state !== void 0 && s !== void 0), "You should avoid providing a 2nd state argument to push when the 1st argument is a location-like object that already has state; it is ignored");
    var t = "PUSH", i = U(a, s, N(), _.location);
    b.confirmTransitionTo(i, t, h, function(c) {
      if (c) {
        var l = u(i), A = i.key, O = i.state;
        if (d)
          if (n.pushState({
            key: A,
            state: O
          }, null, l), g)
            window.location.href = l;
          else {
            var w = T.indexOf(_.location.key), W = T.slice(0, w + 1);
            W.push(i.key), T = W, D({
              action: t,
              location: i
            });
          }
        else
          process.env.NODE_ENV !== "production" && k(O === void 0, "Browser history cannot push state in browsers that do not support HTML5 history"), window.location.href = l;
      }
    });
  }
  function E(a, s) {
    process.env.NODE_ENV !== "production" && k(!(typeof a == "object" && a.state !== void 0 && s !== void 0), "You should avoid providing a 2nd state argument to replace when the 1st argument is a location-like object that already has state; it is ignored");
    var t = "REPLACE", i = U(a, s, N(), _.location);
    b.confirmTransitionTo(i, t, h, function(c) {
      if (c) {
        var l = u(i), A = i.key, O = i.state;
        if (d)
          if (n.replaceState({
            key: A,
            state: O
          }, null, l), g)
            window.location.replace(l);
          else {
            var w = T.indexOf(_.location.key);
            w !== -1 && (T[w] = i.key), D({
              action: t,
              location: i
            });
          }
        else
          process.env.NODE_ENV !== "production" && k(O === void 0, "Browser history cannot replace state in browsers that do not support HTML5 history"), window.location.replace(l);
      }
    });
  }
  function P(a) {
    n.go(a);
  }
  function x() {
    P(-1);
  }
  function C() {
    P(1);
  }
  var j = 0;
  function S(a) {
    j += a, j === 1 && a === 1 ? (window.addEventListener(ie, V), f && window.addEventListener(ae, B)) : j === 0 && (window.removeEventListener(ie, V), f && window.removeEventListener(ae, B));
  }
  var L = !1;
  function Y(a) {
    a === void 0 && (a = !1);
    var s = b.setPrompt(a);
    return L || (S(1), L = !0), function() {
      return L && (L = !1, S(-1)), s();
    };
  }
  function G(a) {
    var s = b.appendListener(a);
    return S(1), function() {
      S(-1), s();
    };
  }
  var _ = {
    length: n.length,
    action: "POP",
    location: $,
    createHref: u,
    push: r,
    replace: E,
    go: P,
    goBack: x,
    goForward: C,
    block: Y,
    listen: G
  };
  return _;
}
var se = "hashchange", Ee = {
  hashbang: {
    encodePath: function(n) {
      return n.charAt(0) === "!" ? n : "!/" + oe(n);
    },
    decodePath: function(n) {
      return n.charAt(0) === "!" ? n.substr(1) : n;
    }
  },
  noslash: {
    encodePath: oe,
    decodePath: z
  },
  slash: {
    encodePath: z,
    decodePath: z
  }
};
function le(e) {
  var n = e.indexOf("#");
  return n === -1 ? e : e.slice(0, n);
}
function K() {
  var e = window.location.href, n = e.indexOf("#");
  return n === -1 ? "" : e.substring(n + 1);
}
function Pe(e) {
  window.location.hash = e;
}
function Z(e) {
  window.location.replace(le(window.location.href) + "#" + e);
}
function He(e) {
  e === void 0 && (e = {}), he || (process.env.NODE_ENV !== "production" ? Q(!1, "Hash history needs a DOM") : Q(!1));
  var n = window.history, d = we(), f = e, o = f.getUserConfirmation, p = o === void 0 ? ue : o, g = f.hashType, y = g === void 0 ? "slash" : g, h = e.basename ? de(z(e.basename)) : "", v = Ee[y], m = v.encodePath, H = v.decodePath;
  function M() {
    var t = H(K());
    return process.env.NODE_ENV !== "production" && k(!h || ee(t, h), 'You are attempting to use a basename on a page whose URL path does not begin with the basename. Expected path "' + t + '" to begin with "' + h + '".'), h && (t = fe(t, h)), U(t);
  }
  var N = ne();
  function b(t) {
    X(s, t), s.length = n.length, N.notifyListeners(s.location, s.action);
  }
  var D = !1, V = null;
  function B(t, i) {
    return t.pathname === i.pathname && t.search === i.search && t.hash === i.hash;
  }
  function R() {
    var t = K(), i = m(t);
    if (t !== i)
      Z(i);
    else {
      var c = M(), l = s.location;
      if (!D && B(l, c) || V === I(c))
        return;
      V = null, F(c);
    }
  }
  function F(t) {
    if (D)
      D = !1, b();
    else {
      var i = "POP";
      N.confirmTransitionTo(t, i, p, function(c) {
        c ? b({
          action: i,
          location: t
        }) : q(t);
      });
    }
  }
  function q(t) {
    var i = s.location, c = r.lastIndexOf(I(i));
    c === -1 && (c = 0);
    var l = r.lastIndexOf(I(t));
    l === -1 && (l = 0);
    var A = c - l;
    A && (D = !0, C(A));
  }
  var $ = K(), T = m($);
  $ !== T && Z(T);
  var u = M(), r = [I(u)];
  function E(t) {
    var i = document.querySelector("base"), c = "";
    return i && i.getAttribute("href") && (c = le(window.location.href)), c + "#" + m(h + I(t));
  }
  function P(t, i) {
    process.env.NODE_ENV !== "production" && k(i === void 0, "Hash history cannot push state; it is ignored");
    var c = "PUSH", l = U(t, void 0, void 0, s.location);
    N.confirmTransitionTo(l, c, p, function(A) {
      if (A) {
        var O = I(l), w = m(h + O), W = K() !== w;
        if (W) {
          V = O, Pe(w);
          var J = r.lastIndexOf(I(s.location)), te = r.slice(0, J + 1);
          te.push(O), r = te, b({
            action: c,
            location: l
          });
        } else
          process.env.NODE_ENV !== "production" && k(!1, "Hash history cannot PUSH the same path; a new entry will not be added to the history stack"), b();
      }
    });
  }
  function x(t, i) {
    process.env.NODE_ENV !== "production" && k(i === void 0, "Hash history cannot replace state; it is ignored");
    var c = "REPLACE", l = U(t, void 0, void 0, s.location);
    N.confirmTransitionTo(l, c, p, function(A) {
      if (A) {
        var O = I(l), w = m(h + O), W = K() !== w;
        W && (V = O, Z(w));
        var J = r.indexOf(I(s.location));
        J !== -1 && (r[J] = O), b({
          action: c,
          location: l
        });
      }
    });
  }
  function C(t) {
    process.env.NODE_ENV !== "production" && k(d, "Hash history go(n) causes a full page reload in this browser"), n.go(t);
  }
  function j() {
    C(-1);
  }
  function S() {
    C(1);
  }
  var L = 0;
  function Y(t) {
    L += t, L === 1 && t === 1 ? window.addEventListener(se, R) : L === 0 && window.removeEventListener(se, R);
  }
  var G = !1;
  function _(t) {
    t === void 0 && (t = !1);
    var i = N.setPrompt(t);
    return G || (Y(1), G = !0), function() {
      return G && (G = !1, Y(-1)), i();
    };
  }
  function a(t) {
    var i = N.appendListener(t);
    return Y(1), function() {
      Y(-1), i();
    };
  }
  var s = {
    length: n.length,
    action: "POP",
    location: u,
    createHref: E,
    push: P,
    replace: x,
    go: C,
    goBack: j,
    goForward: S,
    block: _,
    listen: a
  };
  return s;
}
function ce(e, n, d) {
  return Math.min(Math.max(e, n), d);
}
function Ne(e) {
  e === void 0 && (e = {});
  var n = e, d = n.getUserConfirmation, f = n.initialEntries, o = f === void 0 ? ["/"] : f, p = n.initialIndex, g = p === void 0 ? 0 : p, y = n.keyLength, h = y === void 0 ? 6 : y, v = ne();
  function m(r) {
    X(u, r), u.length = u.entries.length, v.notifyListeners(u.location, u.action);
  }
  function H() {
    return Math.random().toString(36).substr(2, h);
  }
  var M = ce(g, 0, o.length - 1), N = o.map(function(r) {
    return typeof r == "string" ? U(r, void 0, H()) : U(r, void 0, r.key || H());
  }), b = I;
  function D(r, E) {
    process.env.NODE_ENV !== "production" && k(!(typeof r == "object" && r.state !== void 0 && E !== void 0), "You should avoid providing a 2nd state argument to push when the 1st argument is a location-like object that already has state; it is ignored");
    var P = "PUSH", x = U(r, E, H(), u.location);
    v.confirmTransitionTo(x, P, d, function(C) {
      if (C) {
        var j = u.index, S = j + 1, L = u.entries.slice(0);
        L.length > S ? L.splice(S, L.length - S, x) : L.push(x), m({
          action: P,
          location: x,
          index: S,
          entries: L
        });
      }
    });
  }
  function V(r, E) {
    process.env.NODE_ENV !== "production" && k(!(typeof r == "object" && r.state !== void 0 && E !== void 0), "You should avoid providing a 2nd state argument to replace when the 1st argument is a location-like object that already has state; it is ignored");
    var P = "REPLACE", x = U(r, E, H(), u.location);
    v.confirmTransitionTo(x, P, d, function(C) {
      C && (u.entries[u.index] = x, m({
        action: P,
        location: x
      }));
    });
  }
  function B(r) {
    var E = ce(u.index + r, 0, u.entries.length - 1), P = "POP", x = u.entries[E];
    v.confirmTransitionTo(x, P, d, function(C) {
      C ? m({
        action: P,
        location: x,
        index: E
      }) : m();
    });
  }
  function R() {
    B(-1);
  }
  function F() {
    B(1);
  }
  function q(r) {
    var E = u.index + r;
    return E >= 0 && E < u.entries.length;
  }
  function $(r) {
    return r === void 0 && (r = !1), v.setPrompt(r);
  }
  function T(r) {
    return v.appendListener(r);
  }
  var u = {
    length: N.length,
    action: "POP",
    location: N[M],
    index: M,
    entries: N,
    createHref: b,
    push: D,
    replace: V,
    go: B,
    goBack: R,
    goForward: F,
    canGo: q,
    block: $,
    listen: T
  };
  return u;
}
export {
  ke as createBrowserHistory,
  He as createHashHistory,
  U as createLocation,
  Ne as createMemoryHistory,
  I as createPath,
  pe as parsePath
};
