import { useEditorState as E } from "@udecode/plate-core";
import { useState as p, useCallback as T, useEffect as y } from "react";
import { usePopper as S } from "react-popper";
import { DEFAULT_TEXT_STYLE_VALUE as w } from "../types.es.js";
import { selectedTextStyles as x } from "./selectedTextStyles.es.js";
import { verticalPositionModifier as L } from "./verticalPositionModifier.es.js";
const A = (a) => {
  const [n, e] = p(!1), [t, c] = p(null), [o, d] = p(null), l = E(a), s = x(l);
  let i = w;
  s.length === 1 ? i = s[0] : s.length === 0 && (i = "p");
  const u = T(() => {
    e((r) => !r);
  }, [e]), f = S(t, o, {
    placement: "bottom-start",
    strategy: "fixed",
    modifiers: [
      {
        name: "offset",
        options: {
          offset: [0, 6]
        }
      },
      {
        name: "flip",
        enabled: !1
      },
      L
    ]
  });
  return y(() => {
    const r = (g) => {
      if (n) {
        const m = g.target;
        if (o && o.contains(m) || t && t.contains(m))
          return;
        e(!1);
      }
    };
    return document.addEventListener("pointerdown", r), () => {
      document.removeEventListener("pointerdown", r);
    };
  }, [n, o, e, t]), {
    state: { isOpen: n, toggle: u, editor: l },
    dropdownProps: {
      ...f.attributes.popper,
      style: f.styles.popper
    },
    key: i,
    dropdownRef: d,
    triggerRef: c
  };
};
export {
  A as useTextStyleDropdown
};
//# sourceMappingURL=useTextStyleDropdown.es.js.map
