import "./dayjs.min-D5mIeZ1x.js";
import "./app-Bpb4394e.js";
function m(a) {
  function t(o, n = !0) {
    const e = Math.round(Math.log10(o));
    return isFinite(e) && e >= 0 ? Math.ceil(e) : n ? 0 : Math.floor(e);
  }
  function r(o) {
    const n = o.conversion;
    return i - n.precision + t(n.amount);
  }
  const i = a.precision;
  return a.measurements.reduce((o, n) => {
    const e = r(n);
    return e > o ? e : o;
  }, 0);
}
class c {
  static toDouble(t) {
    return t.amount / Math.pow(10, t.precision);
  }
  static multiplyDecimal(t, r) {
    let i = t.amount * r.amount, o = i == 0 ? 0 : t.precision + r.precision, n = i.toString();
    for (; n.length > 0 && n[n.length - 1] == "0" && o > 0; )
      i = i / 10, o -= 1, n = i.toString();
    return {
      amount: i,
      precision: o
    };
  }
  static divide(t, r) {
    return {
      amount: Math.floor(t.amount / r),
      precision: t.precision
    };
  }
  /// Adds two decimals and returns result of any max precision from [left] or [right]
  static addDecimal(t, r) {
    const i = c.normalize([t, r]), o = i[0], n = i[1];
    return {
      amount: o.amount + n.amount,
      precision: o.precision
    };
  }
  /// Multiplies amount if new precision is higher or rounds amount if new precision is lower
  ///
  /// e.g. 0.4  to 2 precision --> 0.40
  ///      0.47 to 1 precision --> 0.5
  ///      0.22 to 1 precision --> 0.0
  static toPrecision(t, r) {
    function i(n, e) {
      let s = n.amount;
      for (let u = n.precision; u < e; u++)
        s *= 10;
      return {
        amount: s,
        precision: e
      };
    }
    function o(n, e) {
      let s = n.amount;
      for (let u = n.precision; u > e; u--)
        s /= 10;
      return {
        amount: Number(s.toFixed(0)),
        precision: e
      };
    }
    return t.precision == r ? t : t.precision < r ? i(t, r) : o(t, r);
  }
  static equal(t, r) {
    const i = c.normalize([t, r]), o = i[0], n = i[1];
    return o.amount == n.amount;
  }
  static normalize(t) {
    const r = t.reduce(
      (i, o) => Math.max(i, Math.floor(o.precision)),
      0
    );
    return t.map((i) => c.toPrecision(i, r));
  }
}
function f(a, t, r, i = !0) {
  let o = {
    ...a
  };
  if (r) {
    const n = typeof r == "string" ? t.measurements.find((s) => s.id === r) : r;
    if (!n)
      return "NaN";
    const e = m(t);
    return o.precision < e && (o = c.toPrecision(o, m(t))), o = c.divide(o, c.toDouble(n.conversion)), `${c.toDouble(o)} ${n.abbrev}`;
  }
  return i ? `${c.toDouble(o)} ${t.abbrev}` : c.toDouble(o);
}
export {
  c as F,
  f as g
};
