import j from "../../../../@babel/runtime/helpers/esm/objectSpread2.mjs";
import * as y from "react";
function h(n) {
  var r = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "";
  return typeof r == "number" ? r : r.endsWith("%") ? n * parseFloat(r) / 100 : null;
}
function S(n, r, M) {
  return y.useMemo(function() {
    if (r && r > 0) {
      var c = 0, p = 0;
      n.forEach(function(f) {
        var a = h(r, f.width);
        a ? c += a : p += 1;
      });
      var u = Math.max(r, M), e = Math.max(u - c, p), g = p, m = e / p, w = 0, o = n.map(function(f) {
        var a = j({}, f), v = h(r, a.width);
        if (v)
          a.width = v;
        else {
          var b = Math.floor(m);
          a.width = g === 1 ? e : b, e -= b, g -= 1;
        }
        return w += a.width, a;
      });
      if (w < u) {
        var E = u / w;
        e = u, o.forEach(function(f, a) {
          var v = Math.floor(f.width * E);
          f.width = a === o.length - 1 ? e : v, e -= v;
        });
      }
      return [o, Math.max(w, u)];
    }
    return [n, r];
  }, [n, r, M]);
}
export {
  S as default
};
