import { $ as y } from "./focusWithoutScrolling-CDw3JYiq.es.js";
import { $ as s, a as K, b as u, c as g } from "./platform-Z5fvtFmM.es.js";
import w, { useMemo as x, createContext as A, useContext as m } from "react";
const b = /* @__PURE__ */ A({
  isNative: !0,
  open: _,
  useHref: (e) => e
});
function T(e) {
  let { children: a, navigate: t, useHref: r } = e, d = x(() => ({
    isNative: !1,
    open: (n, i, c, f) => {
      h(n, (o) => {
        v(o, i) ? t(c, f) : l(o, i);
      });
    },
    useHref: r || ((n) => n)
  }), [
    t,
    r
  ]);
  return /* @__PURE__ */ w.createElement(b.Provider, {
    value: d
  }, a);
}
function $() {
  return m(b);
}
function v(e, a) {
  let t = e.getAttribute("target");
  return (!t || t === "_self") && e.origin === location.origin && !e.hasAttribute("download") && !a.metaKey && // open in new tab (mac)
  !a.ctrlKey && // open in new tab (windows)
  !a.altKey && // download
  !a.shiftKey;
}
function l(e, a, t = !0) {
  var r, d;
  let { metaKey: n, ctrlKey: i, altKey: c, shiftKey: f } = a;
  s() && (!((d = window.event) === null || d === void 0 || (r = d.type) === null || r === void 0) && r.startsWith("key")) && e.target === "_blank" && (u() ? n = !0 : i = !0);
  let o = K() && u() && !g() && process.env.NODE_ENV !== "test" ? new KeyboardEvent("keydown", {
    keyIdentifier: "Enter",
    metaKey: n,
    ctrlKey: i,
    altKey: c,
    shiftKey: f
  }) : new MouseEvent("click", {
    metaKey: n,
    ctrlKey: i,
    altKey: c,
    shiftKey: f,
    bubbles: !0,
    cancelable: !0
  });
  l.isOpening = t, y(e), e.dispatchEvent(o), l.isOpening = !1;
}
l.isOpening = !1;
function h(e, a) {
  if (e instanceof HTMLAnchorElement) a(e);
  else if (e.hasAttribute("data-href")) {
    let t = document.createElement("a");
    t.href = e.getAttribute("data-href"), e.hasAttribute("data-target") && (t.target = e.getAttribute("data-target")), e.hasAttribute("data-rel") && (t.rel = e.getAttribute("data-rel")), e.hasAttribute("data-download") && (t.download = e.getAttribute("data-download")), e.hasAttribute("data-ping") && (t.ping = e.getAttribute("data-ping")), e.hasAttribute("data-referrer-policy") && (t.referrerPolicy = e.getAttribute("data-referrer-policy")), e.appendChild(t), a(t), e.removeChild(t);
  }
}
function _(e, a) {
  h(e, (t) => l(t, a));
}
function k(e) {
  let a = $();
  var t;
  const r = a.useHref((t = e.href) !== null && t !== void 0 ? t : "");
  return {
    "data-href": e.href ? r : void 0,
    "data-target": e.target,
    "data-rel": e.rel,
    "data-download": e.download,
    "data-ping": e.ping,
    "data-referrer-policy": e.referrerPolicy
  };
}
function C(e) {
  let a = $();
  var t;
  const r = a.useHref((t = e?.href) !== null && t !== void 0 ? t : "");
  return {
    href: e?.href ? r : void 0,
    target: e?.target,
    rel: e?.rel,
    download: e?.download,
    ping: e?.ping,
    referrerPolicy: e?.referrerPolicy
  };
}
function N(e, a, t, r) {
  !a.isNative && e.currentTarget instanceof HTMLAnchorElement && e.currentTarget.href && // If props are applied to a router Link component, it may have already prevented default.
  !e.isDefaultPrevented() && v(e.currentTarget, e) && t && (e.preventDefault(), a.open(e.currentTarget, e, t, r));
}
export {
  T as $,
  $ as a,
  C as b,
  N as c,
  l as d,
  k as e
};
//# sourceMappingURL=openLink-BNz58j4a.es.js.map
