import d from "../../../@babel/runtime/helpers/esm/classCallCheck.mjs";
import S from "../../../@babel/runtime/helpers/esm/createClass.mjs";
import u from "../../../@babel/runtime/helpers/esm/defineProperty.mjs";
import { trimNumber as l, isEmpty as y, isE as N, num2str as k, validateNumber as p } from "./numberUtil.mjs";
var w = /* @__PURE__ */ function() {
  function a(e) {
    if (d(this, a), u(this, "origin", ""), u(this, "negative", void 0), u(this, "integer", void 0), u(this, "decimal", void 0), u(this, "decimalLen", void 0), u(this, "empty", void 0), u(this, "nan", void 0), y(e)) {
      this.empty = !0;
      return;
    }
    if (this.origin = String(e), e === "-" || Number.isNaN(e)) {
      this.nan = !0;
      return;
    }
    var t = e;
    if (N(t) && (t = Number(t)), t = typeof t == "string" ? t : k(t), p(t)) {
      var i = l(t);
      this.negative = i.negative;
      var n = i.trimStr.split(".");
      this.integer = BigInt(n[0]);
      var r = n[1] || "0";
      this.decimal = BigInt(r), this.decimalLen = r.length;
    } else
      this.nan = !0;
  }
  return S(a, [{
    key: "getMark",
    value: function() {
      return this.negative ? "-" : "";
    }
  }, {
    key: "getIntegerStr",
    value: function() {
      return this.integer.toString();
    }
    /**
     * @private get decimal string
     */
  }, {
    key: "getDecimalStr",
    value: function() {
      return this.decimal.toString().padStart(this.decimalLen, "0");
    }
    /**
     * @private Align BigIntDecimal with same decimal length. e.g. 12.3 + 5 = 1230000
     * This is used for add function only.
     */
  }, {
    key: "alignDecimal",
    value: function(t) {
      var i = "".concat(this.getMark()).concat(this.getIntegerStr()).concat(this.getDecimalStr().padEnd(t, "0"));
      return BigInt(i);
    }
  }, {
    key: "negate",
    value: function() {
      var t = new a(this.toString());
      return t.negative = !t.negative, t;
    }
  }, {
    key: "cal",
    value: function(t, i, n) {
      var r = Math.max(this.getDecimalStr().length, t.getDecimalStr().length), g = this.alignDecimal(r), m = t.alignDecimal(r), h = i(g, m).toString(), s = n(r), c = l(h), v = c.negativeStr, f = c.trimStr, o = "".concat(v).concat(f.padStart(s + 1, "0"));
      return new a("".concat(o.slice(0, -s), ".").concat(o.slice(-s)));
    }
  }, {
    key: "add",
    value: function(t) {
      if (this.isInvalidate())
        return new a(t);
      var i = new a(t);
      return i.isInvalidate() ? this : this.cal(i, function(n, r) {
        return n + r;
      }, function(n) {
        return n;
      });
    }
  }, {
    key: "multi",
    value: function(t) {
      var i = new a(t);
      return this.isInvalidate() || i.isInvalidate() ? new a(NaN) : this.cal(i, function(n, r) {
        return n * r;
      }, function(n) {
        return n * 2;
      });
    }
  }, {
    key: "isEmpty",
    value: function() {
      return this.empty;
    }
  }, {
    key: "isNaN",
    value: function() {
      return this.nan;
    }
  }, {
    key: "isInvalidate",
    value: function() {
      return this.isEmpty() || this.isNaN();
    }
  }, {
    key: "equals",
    value: function(t) {
      return this.toString() === (t == null ? void 0 : t.toString());
    }
  }, {
    key: "lessEquals",
    value: function(t) {
      return this.add(t.negate().toString()).toNumber() <= 0;
    }
  }, {
    key: "toNumber",
    value: function() {
      return this.isNaN() ? NaN : Number(this.toString());
    }
  }, {
    key: "toString",
    value: function() {
      var t = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : !0;
      return t ? this.isInvalidate() ? "" : l("".concat(this.getMark()).concat(this.getIntegerStr(), ".").concat(this.getDecimalStr())).fullStr : this.origin;
    }
  }]), a;
}();
export {
  w as default
};
