import { b9 as T, a0 as o, bP as q, cA as B, ba as L, bd as A, bv as g, bK as U, bb as _, w as j, cn as K, bM as G, f9 as W, bf as z, bB as $, dl as H, bO as X, be as J, c0 as Y, U as Q, V as w, P as f, bh as S, bi as v, bj as h, em as Z, bg as c, bV as ee, bk as te, bl as ae, dn as re, bY as ne, cG as oe, bn as ue, bX as E, dp as ie, dq as le, bp as de, co as se, ca as ce, cb as me, gJ as be, cs as fe, bD as ve, bA as he } from "./684d2f28.js";
import { useContext as m, useRef as pe, useEffect as R, useState as ge } from "react";
import { formDataChildren as we, FormDataPropertyView as Ne } from "./00dac55d.js";
import { focusWithOptions as ye, blurMethod as Se, clickMethod as Ce, selectMethod as xe, setSelectionRangeMethod as Ve, setRangeTextMethod as Me } from "./d6402597.js";
import { fixOldInputCompData as Ie } from "./0c4ef413.js";
import "react-dom";
function M(e, t) {
  return t === void 0 && (t = 15), +parseFloat(Number(e).toPrecision(t));
}
function d(e) {
  var t = e.toString().split(/[eE]/), a = (t[0].split(".")[1] || "").length - +(t[1] || 0);
  return a > 0 ? a : 0;
}
function N(e) {
  if (e.toString().indexOf("e") === -1)
    return Number(e.toString().replace(".", ""));
  var t = d(e);
  return t > 0 ? M(Number(e) * Math.pow(10, t)) : Number(e);
}
function C(e) {
  D && (e > Number.MAX_SAFE_INTEGER || e < Number.MIN_SAFE_INTEGER) && console.warn(e + " is beyond boundary when transfer to integer, the results may not be accurate");
}
function y(e) {
  return function() {
    for (var t = [], a = 0; a < arguments.length; a++)
      t[a] = arguments[a];
    var r = t[0], i = t.slice(1);
    return i.reduce(function(l, s) {
      return e(l, s);
    }, r);
  };
}
var b = y(function(e, t) {
  var a = N(e), r = N(t), i = d(e) + d(t), l = a * r;
  return C(l), l / Math.pow(10, i);
}), $e = y(function(e, t) {
  var a = Math.pow(10, Math.max(d(e), d(t)));
  return (b(e, a) + b(t, a)) / a;
}), Ee = y(function(e, t) {
  var a = Math.pow(10, Math.max(d(e), d(t)));
  return (b(e, a) - b(t, a)) / a;
}), P = y(function(e, t) {
  var a = N(e), r = N(t);
  return C(a), C(r), b(a / r, M(Math.pow(10, d(t) - d(e))));
});
function Re(e, t) {
  var a = Math.pow(10, t), r = P(Math.round(Math.abs(b(e, a))), a);
  return e < 0 && r !== 0 && (r = b(r, -1)), r;
}
var D = !0;
function ke(e) {
  e === void 0 && (e = !0), D = e;
}
var x = {
  strip: M,
  plus: $e,
  minus: Ee,
  times: b,
  divide: P,
  round: Re,
  digitLength: d,
  float2Fixed: N,
  enableBoundaryChecking: ke
};
const Fe = (e) => se`
    border-radius: ${e.radius};
    border-width:${e.borderWidth} !important;
    // still use antd style when disabled
    &:not(.ant-input-number-disabled) {
      color: ${e.text};
      background-color: ${e.background};
      border-color: ${e.border};
      //margin: ${e.margin};	
      padding: 0;	
      width: ${ce(e.margin)};
      &.ant-input-number-focused {
        border-color: ${e.accent};
      }

      &:hover {
        border-color: ${e.accent};
      }

      &::-webkit-input-placeholder {
        color: ${e.text};
        opacity: 0.4;
      }
      .ant-input-number {	
        margin: 0;	
        
      }	
      .ant-input-number-input {	
        margin: 0;	
        padding: ${e.padding};	
        height: ${me(e.margin)};	
        color:${e.text};
        font-family:${e.fontFamily} !important;
        font-weight:${e.textWeight} !important;
        font-size:${e.textSize} !important;
        font-style:${e.fontStyle} !important;
      }

      .ant-input-number-handler-wrap {
        background-color: ${e.background};
        border-radius: 0 ${e.radius} ${e.radius} 0;

        .ant-input-number-handler span {
          color: ${e.text};
          opacity: 0.45;

          &:hover {
            opacity: 1;
          }
        }

        .ant-input-number-handler-up {
          border-top-right-radius: ${e.radius};
        }

        .ant-input-number-handler-down {
          border-bottom-right-radius: ${e.radius};
        }
      }
    }
  `, Pe = T(be)`
  width: 100%;
  ${(e) => e.$style && Fe(e.$style)}
`, De = [{
  label: o("numberInput.standard"),
  value: "standard"
}, {
  label: o("numberInput.percent"),
  value: "percent"
}];
function k(e, t) {
  const a = e.replace(/[^\d.-]/g, "");
  if (a) {
    const r = Number(a);
    if (isFinite(r))
      return r;
  }
  return t ? Number.NaN : 0;
}
function Oe(e) {
  const t = e.toString().split(".");
  return t[0] = t[0].replace(/\B(?=(\d{3})+(?!\d))/g, ","), t.join(".");
}
function Te(e, t, a, r, i) {
  const l = e;
  if (isNaN(l))
    return "";
  let s = l.toFixed(r);
  switch (i && (s = Oe(s)), a) {
    case "standard":
      return s;
    case "percent":
      return s + "%";
  }
}
function qe(e, t, a) {
  const r = e;
  if (isNaN(r))
    return t ? null : 0;
  switch (a) {
    case "standard":
      return r;
    case "percent":
      return x.divide(r, 100);
  }
}
function O(e) {
  if (e.customRule)
    return {
      validateStatus: "error",
      help: e.customRule
    };
  const t = e.value.value;
  return isNaN(t) ? e.required ? {
    validateStatus: "error",
    help: o("prop.required")
  } : {
    validateStatus: ""
  } : e.max !== void 0 && t > e.max ? {
    validateStatus: "error",
    help: o("validationDesc.maxValue", {
      value: t,
      max: e.max
    })
  } : e.min !== void 0 && t < e.min ? {
    validateStatus: "error",
    help: o("validationDesc.minValue", {
      value: t,
      min: e.min
    })
  } : {
    validateStatus: ""
  };
}
const F = fe((e) => {
  if (typeof e == "number")
    return e;
  const t = Number(e);
  return !e || isNaN(t) ? void 0 : t;
}), Be = {
  defaultValue: q("defaultValue"),
  // It is more convenient for string to handle various states, save raw input here
  value: B("value"),
  // It is more convenient for string to handle various states, save raw input here
  placeholder: L,
  disabled: A,
  readOnly: g,
  label: U,
  formatter: _(De, "standard"),
  step: j(K, 1),
  controls: g.DEFAULT_TRUE,
  // Whether to display the increase or decrease button
  precision: G.closed(0, 20, 0),
  thousandsSeparator: g.DEFAULT_TRUE,
  // Whether to display the thousand separator
  allowNull: g,
  onEvent: W,
  viewRef: z,
  style: $(H),
  labelStyle: $(X),
  prefixIcon: J,
  // validation
  required: g,
  min: F,
  max: F,
  customRule: Y,
  ...we
}, Le = (e) => {
  const t = pe(null), a = e.defaultValue.value;
  R(() => {
    let n = 0;
    a === "null" && e.allowNull ? n = NaN : isNaN(Number(a)) || (n = Number(a)), e.value.onChange(n);
  }, [a]);
  const r = (n) => Te(n, e.allowNull, e.formatter, e.precision, e.thousandsSeparator), [i, l] = ge(r(e.value.value)), s = () => {
    const n = e.value.value, u = k(i, e.allowNull);
    e.value.onChange(u), n !== u && e.onEvent("change");
  };
  return R(() => {
    l(r(e.value.value));
  }, [e.value.value, e.allowNull, e.formatter, e.precision, e.thousandsSeparator]), /* @__PURE__ */ w(Pe, {
    ref: (n) => {
      e.viewRef(n), t.current = n;
    },
    value: i,
    controls: e.controls,
    step: e.step,
    disabled: e.disabled,
    readOnly: e.readOnly,
    placeholder: e.placeholder,
    stringMode: !0,
    precision: e.precision,
    $style: e.style,
    prefix: ve(e.prefixIcon) && e.prefixIcon,
    onPressEnter: () => {
      s(), e.onEvent("submit");
    },
    onChangeCapture: (n) => {
      var u;
      l((((u = n.target.value) == null ? void 0 : u.toString()) ?? "").replace("。", "."));
    },
    onStep: (n, u) => {
      const p = x.plus(k(i), x.times(u.type === "up" ? 1 : -1, Number(u.offset)));
      e.value.onChange(p), e.onEvent("change");
    },
    onFocus: () => {
      e.onEvent("focus");
    },
    onBlur: () => {
      s(), e.onEvent("blur");
    },
    onKeyPress: (n) => {
      var I;
      const u = i, p = (I = t.current) == null ? void 0 : I.selectionStart;
      /\d/.test(n.key) || p === 0 && n.key === "-" && !/-/.test(u) || p !== 0 && e.thousandsSeparator && n.key === "," || p !== 0 && e.precision > 0 && // eslint-disable-next-line only-ascii/only-ascii
      (n.key === "." || n.key === "。") && !/[.]/.test(u) || n.preventDefault();
    }
  });
};
let V = function() {
  return new Q(Be, (e) => e.label({
    required: e.required,
    children: /* @__PURE__ */ w(Le, {
      ...e
    }),
    style: e.style,
    labelStyle: e.labelStyle,
    ...O(e)
  })).setPropertyViewFn((e) => /* @__PURE__ */ f(S, {
    children: [/* @__PURE__ */ f(v, {
      name: h.basic,
      children: [e.defaultValue.propertyView({
        label: o("prop.defaultValue")
      }), Z(e), e.formatter.propertyView({
        label: o("numberInput.formatter")
      })]
    }), /* @__PURE__ */ w(Ne, {
      ...e
    }), (m(c).editorModeStatus === "logic" || m(c).editorModeStatus === "both") && /* @__PURE__ */ f(S, {
      children: [/* @__PURE__ */ f(v, {
        name: h.validation,
        children: [ee(e), e.min.propertyView({
          label: o("prop.minimum")
        }), e.max.propertyView({
          label: o("prop.maximum")
        }), e.customRule.propertyView({})]
      }), /* @__PURE__ */ f(v, {
        name: h.interaction,
        children: [e.onEvent.getPropertyView(), te(e), ae(e)]
      })]
    }), (m(c).editorModeStatus === "layout" || m(c).editorModeStatus === "both") && e.label.getPropertyView(), (m(c).editorModeStatus === "logic" || m(c).editorModeStatus === "both") && /* @__PURE__ */ f(v, {
      name: h.advanced,
      children: [e.step.propertyView({
        label: o("numberInput.step")
      }), e.precision.propertyView({
        label: o("numberInput.precision")
      }), e.prefixIcon.propertyView({
        label: o("button.prefixIcon")
      }), e.allowNull.propertyView({
        label: o("numberInput.allowNull")
      }), e.thousandsSeparator.propertyView({
        label: o("numberInput.thousandsSeparator")
      }), e.controls.propertyView({
        label: o("numberInput.controls")
      }), re(e)]
    }), (m(c).editorModeStatus === "layout" || m(c).editorModeStatus === "both") && /* @__PURE__ */ f(S, {
      children: [/* @__PURE__ */ w(v, {
        name: h.style,
        children: e.style.getPropertyView()
      }), /* @__PURE__ */ w(v, {
        name: h.labelStyle,
        children: e.labelStyle.getPropertyView()
      })]
    })]
  })).build();
}();
V = he(V, Ie);
const Ae = ne(V, oe([ye, Se, Ce, xe, Ve, Me])), ze = ue(Ae, [E({
  name: "value",
  desc: o("export.inputValueDesc"),
  depKeys: ["value", "allowNull", "formatter"],
  func: (e) => qe(e.value, e.allowNull, e.formatter)
}), ie, le, E({
  name: "invalid",
  desc: o("export.invalidDesc"),
  depKeys: ["value", "required", "min", "max", "allowNull", "customRule"],
  func: (e) => O({
    ...e,
    value: {
      value: e.value
    }
  }).validateStatus !== ""
}), ...de]);
export {
  ze as NumberInputComp
};
