function M(t) {
  const { containerMargin: e, containerPadding: o, containerWidth: g, cols: a } = t;
  return (g - e[0] * (a - 1) - o[0] * 2) / a;
}
function f(t, e, o) {
  return Number.isFinite(t) ? Math.round(e * t + Math.max(0, t - 1) * o) : t;
}
function m(t, e, o, g, a, i, r) {
  const {
    containerMargin: d,
    containerPadding: c,
    rowHeight: u
  } = t, h = M(t), n = {};
  return r && r.resizing ? (n.width = Math.round(r.resizing.width), n.height = Math.round(r.resizing.height)) : i === "maximize_me" ? (n.width = t.containerWidth - 2 * c[0] - 0, n.height = t.containerHeight - 2 * c[1] - 0) : (n.width = f(g, h, d[0]), n.height = f(a, u, d[1])), r && r.dragging ? (n.top = Math.round(r.dragging.top), n.left = Math.round(r.dragging.left)) : i === "maximize_me" ? (n.left = c[0], n.top = c[1]) : (n.left = Math.round((h + d[0]) * e + c[0]), n.top = Math.round((u + d[1]) * o + c[1])), n;
}
function w(t, e, o, g, a) {
  const { containerMargin: i, cols: r, rowHeight: d, maxRows: c } = t, u = M(t);
  let h = Math.round((o - i[0]) / (u + i[0])), n = Math.round((e - i[1]) / (d + i[1]));
  return h = l(h, 0, r - g), n = l(n, 0, c - a), { x: h, y: n };
}
function x(t, e, o, g, a) {
  const { containerMargin: i, maxRows: r, cols: d, rowHeight: c } = t, u = M(t);
  let h = Math.round((e + i[0]) / (u + i[0])), n = Math.round((o + i[1]) / (c + i[1]));
  return h = l(h, 0, d - g), n = l(n, 0, r - a), { w: h, h: n };
}
function l(t, e, o) {
  return Math.max(Math.min(t, o), e);
}
export {
  M as calcGridColWidth,
  m as calcGridItemPosition,
  f as calcGridItemWHPx,
  x as calcWH,
  w as calcXY,
  l as clamp
};
