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