import { $ as ge } from "./NumberFormatter-DgOUVrge.es.js";
import { a as he, $ as xe } from "./LiveAnnouncer-CsPyaceH.es.js";
import { useRef as I, useEffect as R } from "react";
import { $ as ve } from "./useGlobalListeners-BOOfV5Wh.es.js";
import { c as A } from "./mergeProps-Dsl8k3Ig.es.js";
import { $ as Ee } from "./useLocalizedStringFormatter-DWb0DkHL.es.js";
const Pe = /* @__PURE__ */ new RegExp("^.*\\(.*\\).*$"), De = [
  "latn",
  "arab",
  "hanidec",
  "deva",
  "beng",
  "fullwide"
];
class Se {
  /**
  * Parses the given string to a number. Returns NaN if a valid number could not be parsed.
  */
  parse(t) {
    return F(this.locale, this.options, t).parse(t);
  }
  /**
  * Returns whether the given string could potentially be a valid number. This should be used to
  * validate user input as the user types. If a `minValue` or `maxValue` is provided, the validity
  * of the minus/plus sign characters can be checked.
  */
  isValidPartialNumber(t, e, i) {
    return F(this.locale, this.options, t).isValidPartialNumber(t, e, i);
  }
  /**
  * Returns a numbering system for which the given string is valid in the current locale.
  * If no numbering system could be detected, the default numbering system for the current
  * locale is returned.
  */
  getNumberingSystem(t) {
    return F(this.locale, this.options, t).options.numberingSystem;
  }
  constructor(t, e = {}) {
    this.locale = t, this.options = e;
  }
}
const V = /* @__PURE__ */ new Map();
function F(s, t, e) {
  let i = B(s, t);
  if (!s.includes("-nu-") && !i.isValidPartialNumber(e)) {
    for (let n of De) if (n !== i.options.numberingSystem) {
      let o = B(s + (s.includes("-u-") ? "-nu-" : "-u-nu-") + n, t);
      if (o.isValidPartialNumber(e)) return o;
    }
  }
  return i;
}
function B(s, t) {
  let e = s + (t ? Object.entries(t).sort((n, o) => n[0] < o[0] ? -1 : 1).join() : ""), i = V.get(e);
  return i || (i = new Ne(s, t), V.set(e, i)), i;
}
class Ne {
  parse(t) {
    let e = this.sanitize(t);
    if (this.symbols.group && (e = g(e, this.symbols.group, "")), this.symbols.decimal && (e = e.replace(this.symbols.decimal, ".")), this.symbols.minusSign && (e = e.replace(this.symbols.minusSign, "-")), e = e.replace(this.symbols.numeral, this.symbols.index), this.options.style === "percent") {
      let u = e.indexOf("-");
      e = e.replace("-", ""), e = e.replace("+", "");
      let l = e.indexOf(".");
      l === -1 && (l = e.length), e = e.replace(".", ""), l - 2 === 0 ? e = `0.${e}` : l - 2 === -1 ? e = `0.0${e}` : l - 2 === -2 ? e = "0.00" : e = `${e.slice(0, l - 2)}.${e.slice(l - 2)}`, u > -1 && (e = `-${e}`);
    }
    let i = e ? +e : NaN;
    if (isNaN(i)) return NaN;
    if (this.options.style === "percent") {
      var n, o;
      let u = {
        ...this.options,
        style: "decimal",
        minimumFractionDigits: Math.min(((n = this.options.minimumFractionDigits) !== null && n !== void 0 ? n : 0) + 2, 20),
        maximumFractionDigits: Math.min(((o = this.options.maximumFractionDigits) !== null && o !== void 0 ? o : 0) + 2, 20)
      };
      return new Se(this.locale, u).parse(new ge(this.locale, u).format(i));
    }
    return this.options.currencySign === "accounting" && Pe.test(t) && (i = -1 * i), i;
  }
  sanitize(t) {
    return t = t.replace(this.symbols.literals, ""), this.symbols.minusSign && (t = t.replace("-", this.symbols.minusSign)), this.options.numberingSystem === "arab" && (this.symbols.decimal && (t = t.replace(",", this.symbols.decimal), t = t.replace("،", this.symbols.decimal)), this.symbols.group && (t = g(t, ".", this.symbols.group))), this.symbols.group === "’" && t.includes("'") && (t = g(t, "'", this.symbols.group)), this.options.locale === "fr-FR" && this.symbols.group && (t = g(t, " ", this.symbols.group), t = g(t, /\u00A0/g, this.symbols.group)), t;
  }
  isValidPartialNumber(t, e = -1 / 0, i = 1 / 0) {
    return t = this.sanitize(t), this.symbols.minusSign && t.startsWith(this.symbols.minusSign) && e < 0 ? t = t.slice(this.symbols.minusSign.length) : this.symbols.plusSign && t.startsWith(this.symbols.plusSign) && i > 0 && (t = t.slice(this.symbols.plusSign.length)), this.symbols.group && t.startsWith(this.symbols.group) || this.symbols.decimal && t.indexOf(this.symbols.decimal) > -1 && this.options.maximumFractionDigits === 0 ? !1 : (this.symbols.group && (t = g(t, this.symbols.group, "")), t = t.replace(this.symbols.numeral, ""), this.symbols.decimal && (t = t.replace(this.symbols.decimal, "")), t.length === 0);
  }
  constructor(t, e = {}) {
    this.locale = t, e.roundingIncrement !== 1 && e.roundingIncrement != null && (e.maximumFractionDigits == null && e.minimumFractionDigits == null ? (e.maximumFractionDigits = 0, e.minimumFractionDigits = 0) : e.maximumFractionDigits == null ? e.maximumFractionDigits = e.minimumFractionDigits : e.minimumFractionDigits == null && (e.minimumFractionDigits = e.maximumFractionDigits)), this.formatter = new Intl.NumberFormat(t, e), this.options = this.formatter.resolvedOptions(), this.symbols = Fe(t, this.formatter, this.options, e);
    var i, n;
    this.options.style === "percent" && (((i = this.options.minimumFractionDigits) !== null && i !== void 0 ? i : 0) > 18 || ((n = this.options.maximumFractionDigits) !== null && n !== void 0 ? n : 0) > 18) && console.warn("NumberParser cannot handle percentages with greater than 18 decimal places, please reduce the number in your options.");
  }
}
const L = /* @__PURE__ */ new Set([
  "decimal",
  "fraction",
  "integer",
  "minusSign",
  "plusSign",
  "group"
]), we = [
  0,
  4,
  2,
  1,
  11,
  20,
  3,
  7,
  100,
  21,
  0.1,
  1.1
];
function Fe(s, t, e, i) {
  var n, o, u, l;
  let h = new Intl.NumberFormat(s, {
    ...e,
    // Resets so we get the full range of symbols
    minimumSignificantDigits: 1,
    maximumSignificantDigits: 21,
    roundingIncrement: 1,
    roundingPriority: "auto",
    roundingMode: "halfExpand"
  }), m = h.formatToParts(-10000.111), $ = h.formatToParts(10000.111), c = we.map((a) => h.formatToParts(a));
  var d;
  let b = (d = (n = m.find((a) => a.type === "minusSign")) === null || n === void 0 ? void 0 : n.value) !== null && d !== void 0 ? d : "-", p = (o = $.find((a) => a.type === "plusSign")) === null || o === void 0 ? void 0 : o.value;
  !p && (i?.signDisplay === "exceptZero" || i?.signDisplay === "always") && (p = "+");
  let f = (u = new Intl.NumberFormat(s, {
    ...e,
    minimumFractionDigits: 2,
    maximumFractionDigits: 2
  }).formatToParts(1e-3).find((a) => a.type === "decimal")) === null || u === void 0 ? void 0 : u.value, N = (l = m.find((a) => a.type === "group")) === null || l === void 0 ? void 0 : l.value, x = m.filter((a) => !L.has(a.type)).map((a) => C(a.value)), v = c.flatMap((a) => a.filter((r) => !L.has(r.type)).map((r) => C(r.value))), y = [
    .../* @__PURE__ */ new Set([
      ...x,
      ...v
    ])
  ].sort((a, r) => r.length - a.length), E = y.length === 0 ? new RegExp("[\\p{White_Space}]", "gu") : new RegExp(`${y.join("|")}|[\\p{White_Space}]`, "gu"), P = [
    ...new Intl.NumberFormat(e.locale, {
      useGrouping: !1
    }).format(9876543210)
  ].reverse(), D = new Map(P.map((a, r) => [
    a,
    r
  ])), S = new RegExp(`[${P.join("")}]`, "g");
  return {
    minusSign: b,
    plusSign: p,
    decimal: f,
    group: N,
    literals: E,
    numeral: S,
    index: (a) => String(D.get(a))
  };
}
function g(s, t, e) {
  return s.replaceAll ? s.replaceAll(t, e) : s.split(t).join(e);
}
function C(s) {
  return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
}
var M = {};
M = {
  Empty: "فارغ"
};
var z = {};
z = {
  Empty: "Изпразни"
};
var _ = {};
_ = {
  Empty: "Prázdné"
};
var k = {};
k = {
  Empty: "Tom"
};
var G = {};
G = {
  Empty: "Leer"
};
var K = {};
K = {
  Empty: "Άδειο"
};
var U = {};
U = {
  Empty: "Empty"
};
var j = {};
j = {
  Empty: "Vacío"
};
var W = {};
W = {
  Empty: "Tühjenda"
};
var q = {};
q = {
  Empty: "Tyhjä"
};
var H = {};
H = {
  Empty: "Vide"
};
var O = {};
O = {
  Empty: "ריק"
};
var Y = {};
Y = {
  Empty: "Prazno"
};
var Z = {};
Z = {
  Empty: "Üres"
};
var J = {};
J = {
  Empty: "Vuoto"
};
var X = {};
X = {
  Empty: "空"
};
var Q = {};
Q = {
  Empty: "비어 있음"
};
var ee = {};
ee = {
  Empty: "Tuščias"
};
var te = {};
te = {
  Empty: "Tukšs"
};
var ie = {};
ie = {
  Empty: "Tom"
};
var re = {};
re = {
  Empty: "Leeg"
};
var se = {};
se = {
  Empty: "Pusty"
};
var ae = {};
ae = {
  Empty: "Vazio"
};
var ne = {};
ne = {
  Empty: "Vazio"
};
var oe = {};
oe = {
  Empty: "Gol"
};
var le = {};
le = {
  Empty: "Не заполнено"
};
var me = {};
me = {
  Empty: "Prázdne"
};
var ue = {};
ue = {
  Empty: "Prazen"
};
var ce = {};
ce = {
  Empty: "Prazno"
};
var de = {};
de = {
  Empty: "Tomt"
};
var pe = {};
pe = {
  Empty: "Boş"
};
var fe = {};
fe = {
  Empty: "Пусто"
};
var $e = {};
$e = {
  Empty: "空"
};
var be = {};
be = {
  Empty: "空白"
};
var ye = {};
ye = {
  "ar-AE": M,
  "bg-BG": z,
  "cs-CZ": _,
  "da-DK": k,
  "de-DE": G,
  "el-GR": K,
  "en-US": U,
  "es-ES": j,
  "et-EE": W,
  "fi-FI": q,
  "fr-FR": H,
  "he-IL": O,
  "hr-HR": Y,
  "hu-HU": Z,
  "it-IT": J,
  "ja-JP": X,
  "ko-KR": Q,
  "lt-LT": ee,
  "lv-LV": te,
  "nb-NO": ie,
  "nl-NL": re,
  "pl-PL": se,
  "pt-BR": ae,
  "pt-PT": ne,
  "ro-RO": oe,
  "ru-RU": le,
  "sk-SK": me,
  "sl-SI": ue,
  "sr-SP": ce,
  "sv-SE": de,
  "tr-TR": pe,
  "uk-UA": fe,
  "zh-CN": $e,
  "zh-TW": be
};
function Te(s) {
  return s && s.__esModule ? s.default : s;
}
function Ce(s) {
  const t = I(void 0);
  let { value: e, textValue: i, minValue: n, maxValue: o, isDisabled: u, isReadOnly: l, isRequired: h, onIncrement: m, onIncrementPage: $, onDecrement: c, onDecrementPage: d, onDecrementToMin: b, onIncrementToMax: p } = s;
  const T = Ee(Te(ye), "@react-aria/spinbutton"), f = () => clearTimeout(t.current);
  R(() => () => f(), []);
  let N = (r) => {
    if (!(r.ctrlKey || r.metaKey || r.shiftKey || r.altKey || l || r.nativeEvent.isComposing))
      switch (r.key) {
        case "PageUp":
          if ($) {
            r.preventDefault(), $?.();
            break;
          }
        // fallthrough!
        case "ArrowUp":
        case "Up":
          m && (r.preventDefault(), m?.());
          break;
        case "PageDown":
          if (d) {
            r.preventDefault(), d?.();
            break;
          }
        // fallthrough
        case "ArrowDown":
        case "Down":
          c && (r.preventDefault(), c?.());
          break;
        case "Home":
          b && (r.preventDefault(), b?.());
          break;
        case "End":
          p && (r.preventDefault(), p?.());
          break;
      }
  }, x = I(!1), v = () => {
    x.current = !0;
  }, y = () => {
    x.current = !1;
  }, E = i === "" ? T.format("Empty") : (i || `${e}`).replace("-", "−");
  R(() => {
    x.current && (he("assertive"), xe(E, "assertive"));
  }, [
    E
  ]);
  const P = A((r) => {
    f(), m?.(), t.current = window.setTimeout(() => {
      (o === void 0 || isNaN(o) || e === void 0 || isNaN(e) || e < o) && P(60);
    }, r);
  }), D = A((r) => {
    f(), c?.(), t.current = window.setTimeout(() => {
      (n === void 0 || isNaN(n) || e === void 0 || isNaN(e) || e > n) && D(60);
    }, r);
  });
  let S = (r) => {
    r.preventDefault();
  }, { addGlobalListener: w, removeAllGlobalListeners: a } = ve();
  return {
    spinButtonProps: {
      role: "spinbutton",
      "aria-valuenow": e !== void 0 && !isNaN(e) ? e : void 0,
      "aria-valuetext": E,
      "aria-valuemin": n,
      "aria-valuemax": o,
      "aria-disabled": u || void 0,
      "aria-readonly": l || void 0,
      "aria-required": h || void 0,
      onKeyDown: N,
      onFocus: v,
      onBlur: y
    },
    incrementButtonProps: {
      onPressStart: () => {
        P(400), w(window, "contextmenu", S);
      },
      onPressEnd: () => {
        f(), a();
      },
      onFocus: v,
      onBlur: y
    },
    decrementButtonProps: {
      onPressStart: () => {
        D(400), w(window, "contextmenu", S);
      },
      onPressEnd: () => {
        f(), a();
      },
      onFocus: v,
      onBlur: y
    }
  };
}
export {
  Se as $,
  Ce as a
};
//# sourceMappingURL=useSpinButton-D8B_x4uj.es.js.map
