import n, { useState as u, useEffect as s, useContext as b } from "react";
import { $ as v } from "./SSRProvider-eIEwc-2s.es.js";
const p = /* @__PURE__ */ new Set([
  "Arab",
  "Syrc",
  "Samr",
  "Mand",
  "Thaa",
  "Mend",
  "Nkoo",
  "Adlm",
  "Rohg",
  "Hebr"
]), m = /* @__PURE__ */ new Set([
  "ae",
  "ar",
  "arc",
  "bcc",
  "bqi",
  "ckb",
  "dv",
  "fa",
  "glk",
  "he",
  "ku",
  "mzn",
  "nqo",
  "pnb",
  "ps",
  "sd",
  "ug",
  "ur",
  "yi"
]);
function i(e) {
  if (Intl.Locale) {
    let t = new Intl.Locale(e).maximize(), l = typeof t.getTextInfo == "function" ? t.getTextInfo() : t.textInfo;
    if (l) return l.direction === "rtl";
    if (t.script) return p.has(t.script);
  }
  let a = e.split("-")[0];
  return m.has(a);
}
const g = /* @__PURE__ */ Symbol.for("react-aria.i18n.locale");
function d() {
  let e = typeof window < "u" && window[g] || typeof navigator < "u" && (navigator.language || navigator.userLanguage) || "en-US";
  try {
    Intl.DateTimeFormat.supportedLocalesOf([
      e
    ]);
  } catch {
    e = "en-US";
  }
  return {
    locale: e,
    direction: i(e) ? "rtl" : "ltr"
  };
}
let o = /* @__PURE__ */ d(), r = /* @__PURE__ */ new Set();
function f() {
  o = d();
  for (let e of r) e(o);
}
function $() {
  let e = v(), [a, t] = u(o);
  return s(() => (r.size === 0 && window.addEventListener("languagechange", f), r.add(t), () => {
    r.delete(t), r.size === 0 && window.removeEventListener("languagechange", f);
  }), []), e ? {
    locale: "en-US",
    direction: "ltr"
  } : a;
}
const c = /* @__PURE__ */ n.createContext(null);
function h(e) {
  let { locale: a, children: t } = e, l = n.useMemo(() => ({
    locale: a,
    direction: i(a) ? "rtl" : "ltr"
  }), [
    a
  ]);
  return /* @__PURE__ */ n.createElement(c.Provider, {
    value: l
  }, t);
}
function x(e) {
  let { children: a } = e, t = $();
  return /* @__PURE__ */ n.createElement(c.Provider, {
    value: t
  }, a);
}
function w(e) {
  let { locale: a, children: t } = e;
  return a ? /* @__PURE__ */ n.createElement(h, {
    locale: a,
    children: t
  }) : /* @__PURE__ */ n.createElement(x, {
    children: t
  });
}
function I() {
  let e = $();
  return b(c) || e;
}
export {
  I as $,
  w as a
};
//# sourceMappingURL=context-DW7UvQ8z.es.js.map
