import n, { useState as s, useEffect as b, useContext as v } from "react";
import { $ as p } from "./SSRProvider-CQ9PmFV6.es.js";
const m = /* @__PURE__ */ new Set([
  "Arab",
  "Syrc",
  "Samr",
  "Mand",
  "Thaa",
  "Mend",
  "Nkoo",
  "Adlm",
  "Rohg",
  "Hebr"
]), g = /* @__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(), r = typeof t.getTextInfo == "function" ? t.getTextInfo() : t.textInfo;
    if (r) return r.direction === "rtl";
    if (t.script) return m.has(t.script);
  }
  let a = e.split("-")[0];
  return g.has(a);
}
const d = /* @__PURE__ */ Symbol.for("react-aria.i18n.locale");
function u() {
  let e = typeof window < "u" && window[d] || 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__ */ u(), l = /* @__PURE__ */ new Set();
function f() {
  o = u();
  for (let e of l) e(o);
}
function $() {
  let e = p(), [a, t] = s(o);
  return b(() => (l.size === 0 && window.addEventListener("languagechange", f), l.add(t), () => {
    l.delete(t), l.size === 0 && window.removeEventListener("languagechange", f);
  }), []), e ? {
    locale: typeof window < "u" && window[d] || "en-US",
    direction: "ltr"
  } : a;
}
const c = /* @__PURE__ */ n.createContext(null);
function h(e) {
  let { locale: a, children: t } = e, r = n.useMemo(() => ({
    locale: a,
    direction: i(a) ? "rtl" : "ltr"
  }), [
    a
  ]);
  return /* @__PURE__ */ n.createElement(c.Provider, {
    value: r
  }, t);
}
function x(e) {
  let { children: a } = e, t = $();
  return /* @__PURE__ */ n.createElement(c.Provider, {
    value: t
  }, a);
}
function S(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 v(c) || e;
}
export {
  I as $,
  S as a
};
//# sourceMappingURL=context-BfHy4NgG.es.js.map
