var j = Object.defineProperty, D = Object.defineProperties, A = Object.getOwnPropertyDescriptors, I = Object.getOwnPropertySymbols, M = Object.prototype.hasOwnProperty, S = Object.prototype.propertyIsEnumerable, O = (r, e, n) => e in r ? j(r, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : r[e] = n, P = (r, e) => {
  for (var n in e || (e = {}))
    M.call(e, n) && O(r, n, e[n]);
  if (I)
    for (var n of I(e))
      S.call(e, n) && O(r, n, e[n]);
  return r;
}, h = (r, e) => D(r, A(e));
function B(r, e, n) {
  if (e === n)
    return r;
  const p = r.slice();
  return p.splice(n, 0, p.splice(e, 1)[0]), p;
}
function E(r, e, n) {
  var p, _;
  const { source: l, target: o, canceled: y } = e.operation;
  if (!l || !o || y)
    return "preventDefault" in e && e.preventDefault(), r;
  const s = (t, u) => t === u || typeof t == "object" && "id" in t && t.id === u;
  if (Array.isArray(r)) {
    const t = r.findIndex((a) => s(a, l.id)), u = r.findIndex((a) => s(a, o.id));
    if (t === -1 || u === -1)
      return r;
    if (!y && "index" in l && typeof l.index == "number") {
      const a = l.index;
      if (a !== t)
        return n(r, t, a);
    }
    return n(r, t, u);
  }
  const w = Object.entries(r);
  let c = -1, i, f = -1, d;
  for (const [t, u] of w)
    if (c === -1 && (c = u.findIndex((a) => s(a, l.id)), c !== -1 && (i = t)), f === -1 && (f = u.findIndex((a) => s(a, o.id)), f !== -1 && (d = t)), c !== -1 && f !== -1)
      break;
  if (!l.manager) return r;
  const { dragOperation: g } = l.manager, x = (_ = (p = g.shape) == null ? void 0 : p.current.center) != null ? _ : g.position.current;
  if (d == null && o.id in r) {
    const t = o.shape && x.y > o.shape.center.y ? r[o.id].length : 0;
    d = o.id, f = t;
  }
  if (i == null || d == null || i === d && c === f)
    return "preventDefault" in e && e.preventDefault(), r;
  if (i === d)
    return h(P({}, r), {
      [i]: n(r[i], c, f)
    });
  const v = o.shape && Math.round(x.y) > Math.round(o.shape.center.y) ? 1 : 0, b = r[i][c];
  return h(P({}, r), {
    [i]: [
      ...r[i].slice(0, c),
      ...r[i].slice(c + 1)
    ],
    [d]: [
      ...r[d].slice(0, f + v),
      b,
      ...r[d].slice(f + v)
    ]
  });
}
function N(r, e) {
  return E(r, e, B);
}
export {
  B as arrayMove,
  N as move
};
//# sourceMappingURL=index.js.map
