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