import { $ as A } from "./focusWithoutScrolling-CDw3JYiq.es.js";
import x, { useMemo as K, createContext as _, useContext as m } from "react";
function b(e) {
  var a;
  if (typeof window > "u" || window.navigator == null) return !1;
  let t = (a = window.navigator.userAgentData) === null || a === void 0 ? void 0 : a.brands;
  return Array.isArray(t) && t.some((n) => e.test(n.brand)) || e.test(window.navigator.userAgent);
}
function s(e) {
  var a;
  return typeof window < "u" && window.navigator != null ? e.test(((a = window.navigator.userAgentData) === null || a === void 0 ? void 0 : a.platform) || window.navigator.platform) : !1;
}
function r(e) {
  if (process.env.NODE_ENV === "test") return e;
  let a = null;
  return () => (a == null && (a = e()), a);
}
const $ = /* @__PURE__ */ r(function() {
  return s(/^Mac/i);
}), E = /* @__PURE__ */ r(function() {
  return s(/^iPhone/i);
}), v = /* @__PURE__ */ r(function() {
  return s(/^iPad/i) || // iPadOS 13 lies and says it's a Mac, but we can distinguish by detecting touch support.
  $() && navigator.maxTouchPoints > 1;
}), P = /* @__PURE__ */ r(function() {
  return E() || v();
}), M = /* @__PURE__ */ r(function() {
  return $() || P();
}), D = /* @__PURE__ */ r(function() {
  return b(/AppleWebKit/i) && !H();
}), H = /* @__PURE__ */ r(function() {
  return b(/Chrome/i);
}), O = /* @__PURE__ */ r(function() {
  return b(/Android/i);
}), N = /* @__PURE__ */ r(function() {
  return b(/Firefox/i);
}), h = /* @__PURE__ */ _({
  isNative: !0,
  open: T,
  useHref: (e) => e
});
function L(e) {
  let { children: a, navigate: t, useHref: n } = e, d = K(() => ({
    isNative: !1,
    open: (i, o, u, l) => {
      g(i, (f) => {
        w(f, o) ? t(u, l) : c(f, o);
      });
    },
    useHref: n || ((i) => i)
  }), [
    t,
    n
  ]);
  return /* @__PURE__ */ x.createElement(h.Provider, {
    value: d
  }, a);
}
function y() {
  return m(h);
}
function w(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 c(e, a, t = !0) {
  var n, d;
  let { metaKey: i, ctrlKey: o, altKey: u, shiftKey: l } = a;
  N() && (!((d = window.event) === null || d === void 0 || (n = d.type) === null || n === void 0) && n.startsWith("key")) && e.target === "_blank" && ($() ? i = !0 : o = !0);
  let f = D() && $() && !v() && process.env.NODE_ENV !== "test" ? new KeyboardEvent("keydown", {
    keyIdentifier: "Enter",
    metaKey: i,
    ctrlKey: o,
    altKey: u,
    shiftKey: l
  }) : new MouseEvent("click", {
    metaKey: i,
    ctrlKey: o,
    altKey: u,
    shiftKey: l,
    detail: 1,
    bubbles: !0,
    cancelable: !0
  });
  c.isOpening = t, A(e), e.dispatchEvent(f), c.isOpening = !1;
}
c.isOpening = !1;
function g(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 T(e, a) {
  g(e, (t) => c(t, a));
}
function S(e) {
  let a = y();
  var t;
  const n = a.useHref((t = e.href) !== null && t !== void 0 ? t : "");
  return {
    "data-href": e.href ? n : void 0,
    "data-target": e.target,
    "data-rel": e.rel,
    "data-download": e.download,
    "data-ping": e.ping,
    "data-referrer-policy": e.referrerPolicy
  };
}
function p(e) {
  let a = y();
  var t;
  const n = a.useHref((t = e?.href) !== null && t !== void 0 ? t : "");
  return {
    href: e?.href ? n : void 0,
    target: e?.target,
    rel: e?.rel,
    download: e?.download,
    ping: e?.ping,
    referrerPolicy: e?.referrerPolicy
  };
}
function R(e, a, t, n) {
  !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() && w(e.currentTarget, e) && t && (e.preventDefault(), a.open(e.currentTarget, e, t, n));
}
export {
  O as $,
  H as a,
  c as b,
  $ as c,
  L as d,
  y as e,
  p as f,
  R as g,
  D as h,
  P as i,
  M as j,
  S as k,
  E as l,
  v as m
};
//# sourceMappingURL=openLink-m90p5mer.es.js.map
