import b, { useMemo as f, useContext as p, useState as g, useEffect as S } from "react";
import { useIsSSR as m } from "../../ssr/dist/module.es.js";
import { LocalizedStringFormatter as L, LocalizedStringDictionary as v } from "../../../@internationalized/string/dist/module.es.js";
const x = /* @__PURE__ */ new Set([
  "Arab",
  "Syrc",
  "Samr",
  "Mand",
  "Thaa",
  "Mend",
  "Nkoo",
  "Adlm",
  "Rohg",
  "Hebr"
]), h = /* @__PURE__ */ new Set([
  "ae",
  "ar",
  "arc",
  "bcc",
  "bqi",
  "ckb",
  "dv",
  "fa",
  "glk",
  "he",
  "ku",
  "mzn",
  "nqo",
  "pnb",
  "ps",
  "sd",
  "ug",
  "ur",
  "yi"
]);
function w(e) {
  if (Intl.Locale) {
    let t = new Intl.Locale(e).maximize().script;
    return x.has(t);
  }
  let a = e.split("-")[0];
  return h.has(a);
}
function d() {
  let e = typeof navigator < "u" && (navigator.language || navigator.userLanguage) || "en-US";
  try {
    Intl.DateTimeFormat.supportedLocalesOf([
      e
    ]);
  } catch {
    e = "en-US";
  }
  return {
    locale: e,
    direction: w(e) ? "rtl" : "ltr"
  };
}
let n = d(), r = /* @__PURE__ */ new Set();
function l() {
  n = d();
  for (let e of r)
    e(n);
}
function y() {
  let e = m(), [a, t] = g(n);
  return S(() => (r.size === 0 && window.addEventListener("languagechange", l), r.add(t), () => {
    r.delete(t), r.size === 0 && window.removeEventListener("languagechange", l);
  }), []), e ? {
    locale: "en-US",
    direction: "ltr"
  } : a;
}
const z = /* @__PURE__ */ b.createContext(null);
function i() {
  let e = y();
  return p(z) || e;
}
const $ = /* @__PURE__ */ new WeakMap();
function C(e) {
  let a = $.get(e);
  return a || (a = new v(e), $.set(e, a)), a;
}
function M(e) {
  let { locale: a } = i(), t = f(
    () => C(e),
    [
      e
    ]
  );
  return f(
    () => new L(a, t),
    [
      a,
      t
    ]
  );
}
let c = /* @__PURE__ */ new Map();
function T(e) {
  let { locale: a } = i(), t = a + (e ? Object.entries(e).sort(
    (u, s) => u[0] < s[0] ? -1 : 1
  ).join() : "");
  if (c.has(t))
    return c.get(t);
  let o = new Intl.Collator(a, e);
  return c.set(t, o), o;
}
export {
  T as useCollator,
  i as useLocale,
  M as useLocalizedStringFormatter
};
//# sourceMappingURL=real-module.es.js.map
