import * as r from "react";
import { useId as a } from "../../../../../../../@base-ui_utils@0.2.4_@types_react@18.3.27_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/@base-ui/utils/esm/useId.js";
import { useIsoLayoutEffect as l } from "../../../../../../../@base-ui_utils@0.2.4_@types_react@18.3.27_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/@base-ui/utils/esm/useIsoLayoutEffect.js";
import { useRefWithInit as f } from "../../../../../../../@base-ui_utils@0.2.4_@types_react@18.3.27_react-dom@18.3.1_react@18.3.1__react@18.3.1/node_modules/@base-ui/utils/esm/useRefWithInit.js";
import { FloatingTreeStore as m } from "./FloatingTreeStore.js";
import { jsx as d } from "react/jsx-runtime";
const i = /* @__PURE__ */ r.createContext(null);
process.env.NODE_ENV !== "production" && (i.displayName = "FloatingNodeContext");
const s = /* @__PURE__ */ r.createContext(null);
process.env.NODE_ENV !== "production" && (s.displayName = "FloatingTreeContext");
const u = () => {
  var t;
  return ((t = r.useContext(i)) == null ? void 0 : t.id) || null;
}, p = (t) => {
  const o = r.useContext(s);
  return t ?? o;
};
function v(t) {
  const o = a(), e = p(t), n = u();
  return l(() => {
    if (!o)
      return;
    const c = {
      id: o,
      parentId: n
    };
    return e == null || e.addNode(c), () => {
      e == null || e.removeNode(c);
    };
  }, [e, o, n]), o;
}
function I(t) {
  const {
    children: o,
    id: e
  } = t, n = u();
  return /* @__PURE__ */ d(i.Provider, {
    value: r.useMemo(() => ({
      id: e,
      parentId: n
    }), [e, n]),
    children: o
  });
}
function T(t) {
  const {
    children: o,
    externalTree: e
  } = t, n = f(() => e ?? new m()).current;
  return /* @__PURE__ */ d(s.Provider, {
    value: n,
    children: o
  });
}
export {
  I as FloatingNode,
  T as FloatingTree,
  v as useFloatingNodeId,
  u as useFloatingParentNodeId,
  p as useFloatingTree
};
