import { cloneLayout as m, cloneLayoutItem as M, compact as I, correctBounds as g } from "../../utils.js";
function A(e, t) {
  const r = y(e);
  let o = r[0];
  for (let i = 1, u = r.length; i < u; i++) {
    const s = r[i];
    t > e[s] && (o = s);
  }
  return o;
}
function E(e, t) {
  if (!t[e])
    throw new Error(
      "ResponsiveReactGridLayout: `cols` entry for breakpoint " + e + " is missing!"
    );
  return t[e];
}
function F(e, t, r, o, i, u, s, c, d) {
  let n = e[r];
  const h = y(t), x = h.indexOf(r);
  let f;
  if (n)
    n = m(n);
  else {
    if (o !== r && e[o])
      f = o;
    else {
      const l = [
        ...h.splice(x),
        ...h.reverse()
      ];
      for (let v = 0, B = l.length; v < B; v++) {
        const L = l[v];
        if (e[L]) {
          f = L;
          break;
        }
      }
    }
    if (f) {
      n = [];
      for (let l = 0, v = e[f].length; l < v; l++) {
        const B = M(e[f][l]);
        if (s[f]) {
          const L = Math.round(B.w * i / s[f]);
          B.w = L;
        }
        n.push(B);
      }
    }
    n || (n = []);
  }
  return n = m(n), I(
    g(n, { cols: i }, c, c),
    u,
    i,
    c,
    d
  );
}
function y(e) {
  return Object.keys(e).sort(function(r, o) {
    return e[r] - e[o];
  });
}
function w(e, t) {
  return e ? Array.isArray(e) ? e : e[t] : [0, 0];
}
function O(e, t, r, o, i, u, s, c, d) {
  if (e[t] && e[t].findIndex((n) => n.i === r.i) === -1) {
    const n = M(r), h = typeof s == "number" ? s : s[t], x = c !== void 0 ? (c + w(i, t)[1] - 2 * w(u, t)[1]) / (h + w(i, t)[1]) : n.h;
    if (n.freeMove) {
      if (n.x = Math.round(o[t] / 4), n.y = Math.round(x / 4), n.w = Math.round(o[t] / 2), n.h = x / 2, t === "xxs") {
        n.visible = !1;
        for (let f = 0; f < e[t].length; f++)
          e[t][f].freeMove && (e[t][f].visible = !1);
        d === "xxs" && (n.visible = !0);
      }
    } else
      n.w = o[t], n.h = Math.round(x * 0.8);
    n.freeMove ? e[t].push(n) : e[t].unshift(n);
  }
}
function G(e, t, r, o, i, u, s, c) {
  const d = {};
  for (const n in e) {
    const h = m(e[n]);
    d[n] = h, O(
      d,
      n,
      t,
      r,
      o,
      i,
      u,
      s,
      c
    );
  }
  return d;
}
function N(e, t) {
  const r = {};
  for (const o in e)
    r[o] = m(e[o], t);
  return r;
}
export {
  O as addLayoutItemToBreakPointIfNoExists,
  G as addLayoutItemToBreakPoints,
  N as cloneLayouts,
  F as findOrGenerateResponsiveLayout,
  A as getBreakpointFromWidth,
  E as getColsFromBreakpoint,
  w as getIndentationValue,
  y as sortBreakpoints
};
