import * as n from "react";
import { UNSAFE_invariant as r, UNSAFE_warning as E, resolveTo as C, UNSAFE_getResolveToMatches as R, joinPaths as S } from "../../@remix-run/router/dist/router.mjs";
import { Action as G, parsePath as K, resolvePath as Q } from "../../@remix-run/router/dist/router.mjs";
/**
 * React Router v6.21.0
 *
 * Copyright (c) Remix Software Inc.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE.md file in the root directory of this source tree.
 *
 * @license MIT
 */
function N() {
  return N = Object.assign ? Object.assign.bind() : function(e) {
    for (var t = 1; t < arguments.length; t++) {
      var a = arguments[t];
      for (var o in a)
        Object.prototype.hasOwnProperty.call(a, o) && (e[o] = a[o]);
    }
    return e;
  }, N.apply(this, arguments);
}
const g = /* @__PURE__ */ n.createContext(null);
process.env.NODE_ENV !== "production" && (g.displayName = "DataRouter");
const V = /* @__PURE__ */ n.createContext(null);
process.env.NODE_ENV !== "production" && (V.displayName = "DataRouterState");
const A = /* @__PURE__ */ n.createContext(null);
process.env.NODE_ENV !== "production" && (A.displayName = "Await");
const d = /* @__PURE__ */ n.createContext(null);
process.env.NODE_ENV !== "production" && (d.displayName = "Navigation");
const h = /* @__PURE__ */ n.createContext(null);
process.env.NODE_ENV !== "production" && (h.displayName = "Location");
const v = /* @__PURE__ */ n.createContext({
  outlet: null,
  matches: [],
  isDataRoute: !1
});
process.env.NODE_ENV !== "production" && (v.displayName = "Route");
const P = /* @__PURE__ */ n.createContext(null);
process.env.NODE_ENV !== "production" && (P.displayName = "RouteError");
function m() {
  return n.useContext(h) != null;
}
function y() {
  return m() || (process.env.NODE_ENV !== "production" ? r(
    !1,
    // TODO: This error is probably because they somehow have 2 versions of the
    // router loaded. We can help them understand how to avoid that.
    "useLocation() may be used only in the context of a <Router> component."
  ) : r(!1)), n.useContext(h).location;
}
const O = "You should call navigate() in a React.useEffect(), not when your component is first rendered.";
function _(e) {
  n.useContext(d).static || n.useLayoutEffect(e);
}
function L() {
  let {
    isDataRoute: e
  } = n.useContext(v);
  return e ? B() : w();
}
function w() {
  m() || (process.env.NODE_ENV !== "production" ? r(
    !1,
    // TODO: This error is probably because they somehow have 2 versions of the
    // router loaded. We can help them understand how to avoid that.
    "useNavigate() may be used only in the context of a <Router> component."
  ) : r(!1));
  let e = n.useContext(g), {
    basename: t,
    future: a,
    navigator: o
  } = n.useContext(d), {
    matches: s
  } = n.useContext(v), {
    pathname: u
  } = y(), p = JSON.stringify(R(s, a.v7_relativeSplatPath)), f = n.useRef(!1);
  return _(() => {
    f.current = !0;
  }), n.useCallback(function(l, i) {
    if (i === void 0 && (i = {}), process.env.NODE_ENV !== "production" && E(f.current, O), !f.current)
      return;
    if (typeof l == "number") {
      o.go(l);
      return;
    }
    let c = C(l, JSON.parse(p), u, i.relative === "path");
    e == null && t !== "/" && (c.pathname = c.pathname === "/" ? t : S([t, c.pathname])), (i.replace ? o.replace : o.push)(c, i.state, i);
  }, [t, o, p, u, e]);
}
const F = /* @__PURE__ */ n.createContext(null);
function I(e) {
  let t = n.useContext(v).outlet;
  return t && /* @__PURE__ */ n.createElement(F.Provider, {
    value: e
  }, t);
}
var U = /* @__PURE__ */ function(e) {
  return e.UseBlocker = "useBlocker", e.UseRevalidator = "useRevalidator", e.UseNavigateStable = "useNavigate", e;
}(U || {}), b = /* @__PURE__ */ function(e) {
  return e.UseBlocker = "useBlocker", e.UseLoaderData = "useLoaderData", e.UseActionData = "useActionData", e.UseRouteError = "useRouteError", e.UseNavigation = "useNavigation", e.UseRouteLoaderData = "useRouteLoaderData", e.UseMatches = "useMatches", e.UseRevalidator = "useRevalidator", e.UseNavigateStable = "useNavigate", e.UseRouteId = "useRouteId", e;
}(b || {});
function D(e) {
  return e + " must be used within a data router.  See https://reactrouter.com/routers/picking-a-router.";
}
function j(e) {
  let t = n.useContext(g);
  return t || (process.env.NODE_ENV !== "production" ? r(!1, D(e)) : r(!1)), t;
}
function J(e) {
  let t = n.useContext(v);
  return t || (process.env.NODE_ENV !== "production" ? r(!1, D(e)) : r(!1)), t;
}
function T(e) {
  let t = J(e), a = t.matches[t.matches.length - 1];
  return a.route.id || (process.env.NODE_ENV !== "production" ? r(!1, e + ' can only be used on routes that contain a unique "id"') : r(!1)), a.route.id;
}
function B() {
  let {
    router: e
  } = j(U.UseNavigateStable), t = T(b.UseNavigateStable), a = n.useRef(!1);
  return _(() => {
    a.current = !0;
  }), n.useCallback(function(s, u) {
    u === void 0 && (u = {}), process.env.NODE_ENV !== "production" && E(a.current, O), a.current && (typeof s == "number" ? e.navigate(s) : e.navigate(s, N({
      fromRouteId: t
    }, u)));
  }, [e, t]);
}
function q(e) {
  let {
    to: t,
    replace: a,
    state: o,
    relative: s
  } = e;
  m() || (process.env.NODE_ENV !== "production" ? r(
    !1,
    // TODO: This error is probably because they somehow have 2 versions of
    // the router loaded. We can help them understand how to avoid that.
    "<Navigate> may be used only in the context of a <Router> component."
  ) : r(!1));
  let {
    future: u,
    static: p
  } = n.useContext(d);
  process.env.NODE_ENV !== "production" && E(!p, "<Navigate> must not be used on the initial render in a <StaticRouter>. This is a no-op, but you should modify your code so the <Navigate> is only ever rendered in response to some user interaction or state change.");
  let {
    matches: f
  } = n.useContext(v), {
    pathname: x
  } = y(), l = L(), i = C(t, R(f, u.v7_relativeSplatPath), x, s === "path"), c = JSON.stringify(i);
  return n.useEffect(() => l(JSON.parse(c), {
    replace: a,
    state: o,
    relative: s
  }), [l, c, s, a, o]), null;
}
function W(e) {
  return I(e.context);
}
new Promise(() => {
});
export {
  q as Navigate,
  G as NavigationType,
  W as Outlet,
  g as UNSAFE_DataRouterContext,
  V as UNSAFE_DataRouterStateContext,
  h as UNSAFE_LocationContext,
  d as UNSAFE_NavigationContext,
  v as UNSAFE_RouteContext,
  K as parsePath,
  Q as resolvePath,
  m as useInRouterContext,
  y as useLocation,
  L as useNavigate,
  I as useOutlet
};
