import { j as P } from "./jsx-runtime-OVHDjVDe.js";
import { l as h, Q as T } from "./css-D6ZBcSwh.js";
import Z, { createContext as w, memo as G, use as H, useRef as _, useCallback as i, useMemo as x, useId as O } from "react";
import { z as d } from "zod";
const b = d.object({
  key: d.string().or(d.number()),
  type: d.string(),
  elementID: d.string().optional(),
  data: h.unknownZ.optional()
}), M = d.object({ source: b, items: d.array(b) }), F = { key: "", type: "" }, p = { source: F, items: [] }, R = "file", Y = { key: "file", type: R }, z = /* @__PURE__ */ new Set(["all", "copyLink"]), B = (t, e) => z.has(t.dataTransfer.effectAllowed) && e.items.length === 0, A = w(null), S = {
  ...p,
  onSuccessfulDrop: () => {
  }
}, y = () => H(A), j = G(
  ({
    children: t,
    useState: e = Z.useState,
    onDropOutside: n
  }) => {
    const o = y(), [l, r] = e(p), c = _(S), a = _(/* @__PURE__ */ new Set()), f = i(
      (s, u, D) => {
        c.current = { source: s, items: u, onSuccessfulDrop: D }, r({ source: s, items: u });
      },
      [r, n]
    ), g = i(
      ({ target: s, dropped: u }) => {
        const D = c.current.items;
        c.current.onSuccessfulDrop?.({ target: s, dropped: u, hauled: D }), c.current = S, r(p);
      },
      [r]
    ), m = i(
      (s) => {
        let u = null;
        a.current.forEach((D) => {
          u == null && (u = D(c.current, s));
        }), u != null && g(u), c.current = S, r(p);
      },
      [r]
    ), E = i((s) => (a.current.add(s), () => a.current.delete(s)), []), k = x(
      () => o ?? { state: l, start: f, end: m, drop: g, bind: E },
      [l, f, m, g, o]
    );
    return /* @__PURE__ */ P.jsx(A, { value: k, children: t });
  }
);
j.displayName = "HaulProvider";
const v = () => {
  const t = _(p), e = y();
  return e == null || (t.current = e.state), t;
}, N = () => {
  const t = y();
  return t == null ? p : t.state;
}, C = ({ type: t, key: e }) => {
  const n = e ?? O(), o = x(() => ({ key: n, type: t }), [n, t]), l = y();
  if (l == null) return { startDrag: () => {
  }, onDragEnd: () => {
  } };
  const { start: r, end: c } = l;
  return {
    startDrag: i((a, f) => r(o, a, f), [r, o]),
    onDragEnd: (a) => c(T.construct({ x: a.screenX, y: a.screenY }))
  };
}, I = ({
  type: t,
  key: e,
  canDrop: n,
  onDrop: o,
  onDragOver: l
}) => {
  const r = v(), c = y();
  if (c == null) return { onDragOver: () => {
  }, onDrop: () => {
  } };
  const { drop: a } = c, f = e ?? O(), g = x(() => ({ key: f, type: t }), [f, t]), m = _({ x: -1, y: -1 }), E = i(
    (s) => {
      s.preventDefault();
      const u = T.construct({ x: s.screenX, y: s.screenY });
      T.equals(u, m.current) || (m.current = u, n(r.current) && l?.({ event: s, ...r.current }));
    },
    [r, n]
  ), k = i(
    (s) => {
      n(r.current) && (s.preventDefault(), a({ target: g, dropped: o({ ...r.current, event: s }) }));
    },
    [r, o, n, a, g]
  );
  return { onDragOver: E, onDrop: k };
}, X = ({
  type: t,
  key: e,
  ...n
}) => {
  const o = e ?? O(), l = x(() => ({ key: o, type: t }), [o, t]), r = C(l), c = I({ ...n, ...l });
  return { ...r, ...c };
}, q = (t) => ({ items: e }) => e.some((n) => n.type === t), L = (t, e) => e.filter((n) => n.type === t), Q = (t, e, n) => i(
  (o) => e({ ...o, items: L(t, o.items) }),
  n
), V = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
  __proto__: null,
  FILE: Y,
  FILE_TYPE: R,
  Provider: j,
  ZERO_DRAGGING_STATE: p,
  ZERO_ITEM: F,
  canDropOfType: q,
  draggingStateZ: M,
  filterByType: L,
  isFileDrag: B,
  itemZ: b,
  useContext: y,
  useDrag: C,
  useDragAndDrop: X,
  useDraggingRef: v,
  useDraggingState: N,
  useDrop: I,
  useFilterByTypeCallback: Q
}, Symbol.toStringTag, { value: "Module" }));
export {
  R as F,
  V as H,
  j as P,
  X as a,
  Q as b,
  I as c,
  q as d,
  L as f,
  N as u
};
