import { jsx as a } from "react/jsx-runtime";
import { flip as l, shift as d, autoUpdate as f } from "@udecode/plate-floating";
import { useRef as g, useEffect as w } from "react";
import { FloatingToolbar as u } from "../../Toolbar/FloatingToolbar.es.js";
const S = ({ children: i }) => {
  const n = g();
  w(() => {
    const o = () => {
      const t = window.getSelection(), e = ((t == null ? void 0 : t.rangeCount) ?? 0) > 0, s = e ? t == null ? void 0 : t.getRangeAt(0).startOffset : void 0, c = e ? t == null ? void 0 : t.getRangeAt(0).endOffset : void 0;
      !(!!t && s !== c && e) && n.current && n.current();
    };
    return document.addEventListener("selectionchange", o), () => document.removeEventListener("selectionchange", o);
  }, []);
  const r = (o, t, e) => {
    n.current = f(o, t, e);
  };
  return /* @__PURE__ */ a(
    u,
    {
      className: "tw-rounded tw-whitespace-nowrap tw-border tw-border-line tw-shadow-lg tw-bg-base tw-flex tw-flex-wrap",
      state: {
        floatingOptions: {
          middleware: [l(), d()],
          whileElementsMounted: r
        }
      },
      children: /* @__PURE__ */ a(
        "div",
        {
          className: "tw-divide-y tw-divide-line",
          "data-selector": "toolbar-floating",
          "data-test-id": "toolbar-floating",
          children: i
        }
      )
    }
  );
};
export {
  S as ToolbarWrapperPositioningFloating
};
//# sourceMappingURL=ToolbarWrapperPositioningFloating.es.js.map
