import { DEFAULT_ROW_HEIGHT as q } from "./constants.js";
const Q = () => {
};
function M(n, e, r) {
  let i = 0, f;
  for (let t = 0, s = n.length; t < s; t++)
    f = n[t].y + L(n[t], e, r), f > i && (i = f);
  return i;
}
function E(n, e) {
  return {
    w: n.w,
    h: n.h,
    x: n.x,
    y: n.y,
    i: n.i,
    minW: n.minW,
    maxW: n.maxW,
    minH: n.minH,
    maxH: n.maxH,
    moved: !!n.moved,
    static: !!n.static,
    // These can be null/undefined
    isDraggable: n.isDraggable,
    isResizable: n.isResizable,
    resizeHandles: n.resizeHandles,
    isBounded: n.isBounded,
    freeMove: n.freeMove,
    colapsed: n.colapsed,
    visible: n.visible,
    ...e
  };
}
function j(n, e) {
  const r = Array(n.length);
  for (let i = 0, f = n.length; i < f; i++)
    r[i] = E(n[i], e);
  return r;
}
function $(n, e, r, i) {
  return !(n.i === e.i || n.x + n.w <= e.x || n.x >= e.x + e.w || n.y + L(n, r, i) <= e.y || n.y >= e.y + L(e, r, i));
}
function V(n, e, r, i, f, t, s, c) {
  const x = r === "vertical", o = r === "horizontal";
  if (x)
    for (e.y = Math.min(M(n, t, s), e.y); e.y > 0 && !b(n, e, t, s); )
      e.y--;
  else if (o)
    for (; e.x > 0 && !b(n, e, t, s); )
      e.x--;
  let v;
  for (; (v = b(n, e, t, s)) && !(r === null && c); )
    if (o ? C(
      f,
      e,
      v.x + v.w,
      "x",
      t,
      s
    ) : C(
      f,
      e,
      v.y + L(v, t, s),
      "y",
      t,
      s
    ), o && e.x + e.w > i)
      for (e.x = i - e.w, e.y++; e.x > 0 && !b(n, e, t, s); )
        e.x--;
  return e.y = Math.max(e.y, 0), e.x = Math.max(e.x, 0), e;
}
function Z(n, e, r, i, f, t) {
  const s = n.filter((u) => !u.freeMove), c = n.filter((u) => u?.freeMove), x = R(s), o = D(s, e), v = Array(s.length);
  for (let u = 0, m = o.length; u < m; u++) {
    let d = E(o[u]);
    d.static || (d = V(
      x,
      d,
      e,
      r,
      o,
      i,
      f,
      t
    ), x.push(d)), v[s.indexOf(o[u])] = d, d.moved = !1;
  }
  return v.concat(c);
}
function Y(n, e) {
  for (let r = 0, i = n.length; r < i; r++)
    if (n[r].i === e)
      return n[r];
}
function R(n) {
  return n.filter((e) => e.static);
}
function _(n, e, r, i) {
  return n.filter((f) => $(f, e, r, i));
}
function b(n, e, r, i) {
  for (let f = 0, t = n.length; f < t; f++)
    if ($(n[f], e, r, i))
      return n[f];
}
function G(n, e) {
  const r = Array(n.length);
  for (let i = 0, f = n.length; i < f; i++)
    e.i === n[i].i ? r[i] = e : r[i] = n[i];
  return r;
}
function l(n, e, r, i, f, t, s, c) {
  const x = f === "horizontal", o = f !== "horizontal", v = e.static;
  if (i) {
    i = !1;
    const u = {
      x: x ? Math.max(e.x - r.w, 0) : r.x,
      y: o ? Math.max(e.y - L(r, s, c), 0) : r.y,
      w: r.w,
      h: L(r, s, c),
      i: "-1"
    };
    if (!b(n, u, s, c))
      return O(
        n,
        r,
        x ? u.x : void 0,
        o ? u.y : void 0,
        i,
        !!v,
        f,
        t,
        s,
        c,
        !1
      );
  }
  return O(
    n,
    r,
    x ? r.x + 1 : void 0,
    o ? r.y + 1 : void 0,
    i,
    !!v,
    f,
    t,
    s,
    c,
    !1
  );
}
function O(n, e, r, i, f, t, s, c, x, o, v) {
  if (e.static && e.isDraggable !== !0 || e.y === i && e.x === r)
    return n;
  const u = e.x, m = e.y;
  typeof r == "number" && (e.x = r), typeof i == "number" && (e.y = i), e.moved = !0;
  let d = D(n, s);
  (s === "vertical" && typeof i == "number" ? m >= i : s === "horizontal" && typeof r == "number" && u >= r) && (d = d.reverse());
  const h = _(d, e, x, o), k = h.length > 0;
  if (k && v)
    return j(n);
  if (k && t)
    return e.x = u, e.y = m, e.moved = !1, n;
  for (let z = 0, F = h.length; z < F; z++) {
    const w = h[z];
    w.moved || (w.static ? n = l(
      n,
      w,
      e,
      f,
      s,
      c,
      x,
      o
    ) : n = l(
      n,
      e,
      w,
      f,
      s,
      c,
      x,
      o
    ));
  }
  return n;
}
function U(n) {
  return n * 100 + "%";
}
function C(n, e, r, i, f, t) {
  e[i] += 1;
  const s = n.map((c) => c.i).indexOf(e.i);
  for (let c = s + 1; c < n.length; c++) {
    const x = n[c];
    if (!x.static) {
      if (x.y > e.y + L(e, f, t))
        break;
      $(e, x, f, t) && C(
        n,
        x,
        r + (i === "x" ? e.w : L(e, f, t)),
        i,
        f,
        t
      );
    }
  }
  e[i] = r;
}
function g({ top: n, left: e, width: r, height: i }) {
  return {
    /*  transform: translate,
        WebkitTransform: translate,
        MozTransform: translate,
        msTransform: translate,
        OTransform: translate, */
    width: `${r}px`,
    height: `${i}px`,
    position: "absolute",
    left: e,
    top: n
  };
}
function B({ top: n, left: e, width: r, height: i }) {
  return {
    top: `${n}px`,
    left: `${e}px`,
    width: `${r}px`,
    height: `${i}px`,
    position: "absolute"
  };
}
function P(n) {
  return n.slice(0).sort(function(e, r) {
    return e.y > r.y || e.y === r.y && e.x > r.x ? 1 : e.y === r.y && e.x === r.x ? 0 : -1;
  });
}
function S(n) {
  return n.slice(0).sort(function(e, r) {
    return e.x > r.x || e.x === r.x && e.y > r.y ? 1 : -1;
  });
}
function D(n, e) {
  return e === "horizontal" ? S(n) : e === "vertical" ? P(n) : n;
}
function I(n, e, r) {
  let i = Y(n, e);
  return i ? (i = r(E(i)), n = G(n, i), [n, i]) : [n, void 0];
}
function p(n, e, r, i) {
  const f = R(n);
  for (let t = 0, s = n.length; t < s; t++) {
    const c = n[t];
    if (c.x + c.w > e.cols && (c.x = e.cols - c.w), c.x < 0 && (c.x = 0, c.w = e.cols), !c.static)
      f.push(c);
    else
      for (; b(f, c, r, i); )
        c.y++;
  }
  return n;
}
function W(n, e, r, i) {
  if (i) {
    let f;
    return r && r > 0 ? f = e / r : f = e / q, f;
  }
  return n;
}
function L(n, e, r) {
  return W(n.h, e, r, n.colapsed);
}
function X(n, e) {
  return n.i !== e.i ? !1 : !(n.x !== e.x || n.y !== e.y || n.w !== e.w || n.h !== e.h || n.colapsed !== e.colapsed || n.visible !== e.visible || n.freeMove !== e.freeMove);
}
function J(n, e) {
  if (n.length !== e.length)
    return !1;
  for (let r = 0; r < n.length; r++)
    if (!X(n[r], e[r]))
      return !1;
  return !0;
}
function A(n, e) {
  if (Object.keys(n).length !== Object.keys(e).length)
    return !1;
  for (const r in n)
    if (e[r]) {
      if (!J(n[r], e[r]))
        return !1;
    } else
      return !1;
  return !0;
}
export {
  M as bottom,
  j as cloneLayout,
  E as cloneLayoutItem,
  $ as collides,
  Z as compact,
  V as compactItem,
  p as correctBounds,
  _ as getAllCollisions,
  b as getFirstCollision,
  W as getH,
  Y as getLayoutItem,
  L as getLayoutItemH,
  R as getStatics,
  J as isEqualLayout,
  X as isEqualLayoutItem,
  A as isEqualLayouts,
  G as modifyLayout,
  O as moveElement,
  l as moveElementAwayFromCollision,
  Q as noop,
  U as perc,
  B as setTopLeft,
  g as setTransform,
  D as sortLayoutItems,
  S as sortLayoutItemsByColRow,
  P as sortLayoutItemsByRowCol,
  I as withLayoutItem
};
