import { useCallback as vr, useState as V, useEffect as B, useContext as pr, createContext as fr, useRef as R, startTransition as F, memo as _r, forwardRef as gr, useMemo as mr, useImperativeHandle as hr } from "react";
import { Droppable as yr, DragDropManager as W, defaultPreset as k } from "../../../../@dnd-kit_dom@0.1.21/node_modules/@dnd-kit/dom/index.js";
import { KeyboardSensor as ie, PointerSensor as se } from "../../../../@dnd-kit_dom@0.1.21/node_modules/@dnd-kit/dom/index.js";
import { useDeepSignal as Dr, useOnValueChange as _, useOnElementChange as xr, useIsomorphicLayoutEffect as G, useLatest as x } from "./hooks.js";
import { deepEqual as K, ValueHistory as Pr, derived as H } from "../../../../@dnd-kit_state@0.1.21/node_modules/@dnd-kit/state/dist/index.js";
import { j as q } from "../../../../../../_virtual/jsx-runtime.js";
import { currentValue as wr } from "./utilities.js";
import { CollisionPriority as J, CollisionType as Q } from "../../../../@dnd-kit_abstract@0.1.21/node_modules/@dnd-kit/abstract/index.js";
import { batch as Or } from "../../../../@preact_signals-core@1.12.0/node_modules/@preact/signals-core/dist/signals-core.module.js";
var Er = Object.defineProperty, Cr = Object.defineProperties, Sr = Object.getOwnPropertyDescriptors, M = Object.getOwnPropertySymbols, U = Object.prototype.hasOwnProperty, X = Object.prototype.propertyIsEnumerable, A = (e, r, t) => r in e ? Er(e, r, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[r] = t, Mr = (e, r) => {
  for (var t in r || (r = {}))
    U.call(r, t) && A(e, t, r[t]);
  if (M)
    for (var t of M(r))
      X.call(r, t) && A(e, t, r[t]);
  return e;
}, br = (e, r) => Cr(e, Sr(r)), kr = (e, r) => {
  var t = {};
  for (var n in e)
    U.call(e, n) && r.indexOf(n) < 0 && (t[n] = e[n]);
  if (e != null && M)
    for (var n of M(e))
      r.indexOf(n) < 0 && X.call(e, n) && (t[n] = e[n]);
  return t;
}, Ir = new W(), Y = fr(
  Ir
), Rr = _r(
  gr(({ children: e }, r) => {
    const [t, n] = V(0), a = R(null), i = R(null), l = mr(
      () => ({
        renderer: {
          get rendering() {
            var s;
            return (s = a.current) != null ? s : Promise.resolve();
          }
        },
        trackRendering(s) {
          a.current || (a.current = new Promise((o) => {
            i.current = o;
          })), F(() => {
            s(), n((o) => o + 1);
          });
        }
      }),
      []
    );
    return G(() => {
      var s;
      (s = i.current) == null || s.call(i), a.current = null;
    }, [e, t]), hr(r, () => l), null;
  })
), I = [void 0, K];
function ee(e) {
  var r = e, {
    children: t,
    onCollision: n,
    onBeforeDragStart: a,
    onDragStart: i,
    onDragMove: l,
    onDragOver: s,
    onDragEnd: o
  } = r, p = kr(r, [
    "children",
    "onCollision",
    "onBeforeDragStart",
    "onDragStart",
    "onDragMove",
    "onDragOver",
    "onDragEnd"
  ]), d;
  const g = R(null), [v, E] = V((d = p.manager) != null ? d : null), { plugins: y, modifiers: P, sensors: m } = p, w = x(a), D = x(i), lr = x(s), cr = x(l), ur = x(o), T = x(n);
  return B(() => {
    var z;
    if (!g.current) throw new Error("Renderer not found");
    const { renderer: dr, trackRendering: C } = g.current, u = (z = p.manager) != null ? z : new W(p);
    return u.renderer = dr, u.monitor.addEventListener("beforedragstart", (f) => {
      const c = w.current;
      c && C(() => c(f, u));
    }), u.monitor.addEventListener(
      "dragstart",
      (f) => {
        var c;
        return (c = D.current) == null ? void 0 : c.call(D, f, u);
      }
    ), u.monitor.addEventListener("dragover", (f) => {
      const c = lr.current;
      c && C(() => c(f, u));
    }), u.monitor.addEventListener("dragmove", (f) => {
      const c = cr.current;
      c && C(() => c(f, u));
    }), u.monitor.addEventListener("dragend", (f) => {
      const c = ur.current;
      c && C(() => c(f, u));
    }), u.monitor.addEventListener(
      "collision",
      (f) => {
        var c;
        return (c = T.current) == null ? void 0 : c.call(T, f, u);
      }
    ), F(() => E(u)), u.destroy;
  }, [p.manager]), _(
    y,
    () => v && (v.plugins = y ?? k.plugins),
    ...I
  ), _(
    m,
    () => v && (v.sensors = m ?? k.sensors),
    ...I
  ), _(
    P,
    () => v && (v.modifiers = P ?? k.modifiers),
    ...I
  ), /* @__PURE__ */ q.jsxs(Y.Provider, { value: v, children: [
    /* @__PURE__ */ q.jsx(Rr, { ref: g, children: t }),
    t
  ] });
}
function Z() {
  return pr(Y);
}
function Lr(e) {
  var r;
  const t = (r = Z()) != null ? r : void 0, [n] = V(() => e(t));
  return n.manager !== t && (n.manager = t), G(n.register, [t, n]), n;
}
var jr = Object.create, $ = Object.defineProperty, Vr = Object.getOwnPropertyDescriptor, rr = (e, r) => (r = Symbol[e]) ? r : Symbol.for("Symbol." + e), b = (e) => {
  throw TypeError(e);
}, Nr = (e, r, t) => r in e ? $(e, r, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[r] = t, Tr = (e) => {
  var r;
  return [, , , jr((r = e?.[rr("metadata")]) != null ? r : null)];
}, er = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"], tr = (e) => e !== void 0 && typeof e != "function" ? b("Function expected") : e, zr = (e, r, t, n, a) => ({ kind: er[e], name: r, metadata: n, addInitializer: (i) => t._ ? b("Already initialized") : a.push(tr(i || null)) }), Hr = (e, r) => Nr(r, rr("metadata"), e[3]), qr = (e, r, t, n) => {
  for (var a = 0, i = e[r >> 1], l = i && i.length; a < l; a++) i[a].call(t);
  return n;
}, nr = (e, r, t, n, a, i) => {
  for (var l, s, o, p, d = r & 7, g = !1, v = !1, E = 2, y = er[d + 5], P = e[E] || (e[E] = []), m = (a = a.prototype, Vr(a, t)), w = n.length - 1; w >= 0; w--)
    o = zr(d, t, s = {}, e[3], P), o.static = g, o.private = v, p = o.access = { has: (D) => t in D }, p.get = (D) => D[t], l = (0, n[w])(m[y], o), s._ = 1, tr(l) && (m[y] = l);
  return m && $(a, t, m), a;
}, ar = (e, r, t) => r.has(e) || b("Cannot " + t), Ar = (e, r, t) => (ar(e, r, "read from private field"), r.get(e)), Br = (e, r, t) => r.has(e) ? b("Cannot add the same private member more than once") : r instanceof WeakSet ? r.add(e) : r.set(e, t), Fr = (e, r, t, n) => (ar(e, r, "write to private field"), r.set(e, t), t), h = class L {
  /**
   * @param {number} Coordinate of the point on the horizontal axis
   * @param {number} Coordinate of the point on the vertical axis
   */
  constructor(r, t) {
    this.x = r, this.y = t;
  }
  /**
   * Returns the delta between this point and another point.
   *
   * @param {Point} a - A point
   * @param {Point} b - Another point
   */
  static delta(r, t) {
    return new L(r.x - t.x, r.y - t.y);
  }
  /**
   * Returns the distance (hypotenuse) between this point and another point.
   *
   * @param {Point} a - A point
   * @param {Point} b - Another point
   */
  static distance(r, t) {
    return Math.hypot(r.x - t.x, r.y - t.y);
  }
  /**
   * Returns true if both points are equal.
   *
   * @param {Point} a - A point
   * @param {Point} b - Another point
   */
  static equals(r, t) {
    return r.x === t.x && r.y === t.y;
  }
  static from({ x: r, y: t }) {
    return new L(r, t);
  }
}, or, ir, j, S, O, N = class extends (j = Pr, ir = [H], or = [H], j) {
  constructor(e) {
    const r = h.from(e);
    super(r, (t, n) => h.equals(t, n)), qr(O, 5, this), Br(this, S, 0), this.velocity = { x: 0, y: 0 };
  }
  get delta() {
    return h.delta(this.current, this.initial);
  }
  get direction() {
    const { current: e, previous: r } = this;
    if (!r) return null;
    const t = {
      x: e.x - r.x,
      y: e.y - r.y
    };
    return !t.x && !t.y ? null : Math.abs(t.x) > Math.abs(t.y) ? t.x > 0 ? "right" : "left" : t.y > 0 ? "down" : "up";
  }
  get current() {
    return super.current;
  }
  set current(e) {
    const { current: r } = this, t = h.from(e), n = {
      x: t.x - r.x,
      y: t.y - r.y
    }, a = Date.now(), i = a - Ar(this, S), l = (s) => Math.round(s / i * 100);
    Or(() => {
      Fr(this, S, a), this.velocity = {
        x: l(n.x),
        y: l(n.y)
      }, super.current = t;
    });
  }
  reset(e = this.defaultValue) {
    super.reset(h.from(e)), this.velocity = { x: 0, y: 0 };
  }
};
O = Tr(j);
S = /* @__PURE__ */ new WeakMap();
nr(O, 2, "delta", ir, N);
nr(O, 2, "direction", or, N);
Hr(O, N);
var sr = /* @__PURE__ */ ((e) => (e.Horizontal = "x", e.Vertical = "y", e))(sr || {});
Object.values(sr);
var Wr = ({
  dragOperation: e,
  droppable: r
}) => {
  const t = e.position.current;
  if (!t)
    return null;
  const { id: n } = r;
  if (!r.shape)
    return null;
  if (r.shape.containsPoint(t)) {
    const a = h.distance(r.shape.center, t);
    return {
      id: n,
      value: 1 / a,
      type: Q.PointerIntersection,
      priority: J.High
    };
  }
  return null;
}, Gr = ({
  dragOperation: e,
  droppable: r
}) => {
  const { shape: t } = e;
  if (!r.shape || !t?.current)
    return null;
  const n = t.current.intersectionArea(r.shape);
  if (n) {
    const { position: a } = e, i = h.distance(r.shape.center, a.current), s = n / (t.current.area + r.shape.area - n) / i;
    return {
      id: r.id,
      value: s,
      type: Q.ShapeIntersection,
      priority: J.Normal
    };
  }
  return null;
}, Kr = (e) => {
  var r;
  return (r = Wr(e)) != null ? r : Gr(e);
};
function te(e) {
  const { collisionDetector: r, data: t, disabled: n, element: a, id: i, accept: l, type: s } = e, o = Lr(
    (d) => new yr(
      br(Mr({}, e), {
        register: !1,
        element: wr(a)
      }),
      d
    )
  ), p = Dr(o);
  return _(i, () => o.id = i), xr(a, (d) => o.element = d), _(
    l,
    () => o.accept = l,
    void 0,
    K
  ), _(
    r,
    () => o.collisionDetector = r ?? Kr
  ), _(t, () => t && (o.data = t)), _(n, () => o.disabled = n === !0), _(s, () => o.type = s), {
    droppable: p,
    get isDropTarget() {
      return p.isDropTarget;
    },
    ref: vr(
      (d) => {
        var g, v;
        !d && ((g = o.element) != null && g.isConnected) && !((v = o.manager) != null && v.dragOperation.status.idle) || (o.element = d ?? void 0);
      },
      [o]
    )
  };
}
function ne(e) {
  const r = Z();
  B(() => {
    if (!r) {
      process.env.NODE_ENV !== "production" && console.warn(
        "useDndMonitor hook was called outside of a DragDropProvider. Make sure your app is wrapped in a DragDropProvider component."
      );
      return;
    }
    const t = Object.entries(e).reduce(
      (n, [a, i]) => {
        if (i) {
          const l = a.replace(/^on/, "").toLowerCase(), s = r.monitor.addEventListener(
            l,
            i
          );
          n.push(s);
        }
        return n;
      },
      []
    );
    return () => t.forEach((n) => n?.());
  }, [r, e]);
}
export {
  ee as DragDropProvider,
  ie as KeyboardSensor,
  se as PointerSensor,
  Z as useDragDropManager,
  ne as useDragDropMonitor,
  te as useDroppable,
  Lr as useInstance
};
//# sourceMappingURL=index.js.map
