import * as l from "react";
import { FOCUSABLE_ATTRIBUTE as C, ACTIVE_KEY as s, SELECTED_KEY as E } from "../utils/constants.js";
function I(e = []) {
  const g = e.map((t) => t == null ? void 0 : t.reference), r = e.map((t) => t == null ? void 0 : t.floating), i = e.map((t) => t == null ? void 0 : t.item), a = e.map((t) => t == null ? void 0 : t.trigger), n = l.useCallback(
    (t) => u(t, e, "reference"),
    // eslint-disable-next-line react-hooks/exhaustive-deps
    g
  ), f = l.useCallback(
    (t) => u(t, e, "floating"),
    // eslint-disable-next-line react-hooks/exhaustive-deps
    r
  ), o = l.useCallback(
    (t) => u(t, e, "item"),
    // eslint-disable-next-line react-hooks/exhaustive-deps
    i
  ), c = l.useCallback(
    (t) => u(t, e, "trigger"),
    // eslint-disable-next-line react-hooks/exhaustive-deps
    a
  );
  return l.useMemo(() => ({
    getReferenceProps: n,
    getFloatingProps: f,
    getItemProps: o,
    getTriggerProps: c
  }), [n, f, o, c]);
}
function u(e, g, r) {
  var f;
  const i = /* @__PURE__ */ new Map(), a = r === "item", n = {};
  r === "floating" && (n.tabIndex = -1, n[C] = "");
  for (const o in e)
    a && e && (o === s || o === E) || (n[o] = e[o]);
  for (let o = 0; o < g.length; o += 1) {
    let c;
    const t = (f = g[o]) == null ? void 0 : f[r];
    typeof t == "function" ? c = e ? t(e) : null : c = t, c && m(n, c, a, i);
  }
  return m(n, e, a, i), n;
}
function m(e, g, r, i) {
  var a;
  for (const n in g) {
    const f = g[n];
    r && (n === s || n === E) || (n.startsWith("on") ? (i.has(n) || i.set(n, []), typeof f == "function" && ((a = i.get(n)) == null || a.push(f), e[n] = (...o) => {
      var c;
      return (c = i.get(n)) == null ? void 0 : c.map((t) => t(...o)).find((t) => t !== void 0);
    })) : e[n] = f);
  }
}
export {
  I as useInteractions
};
