import { useContext, useState } from "react";
import { EditorContext, ModalServiceContext } from "./../../../../ricos-context/index.js";
import { OverflownButtonsToolbar } from "./data-hooks.js";
const useRicosDesktopToolbarActions = () => {
  const editor = useContext(EditorContext);
  const [shouldShowMore, setShouldShowMore] = useState(false);
  const modalService = useContext(ModalServiceContext);
  const closeToolbar = (moreButton) => {
    setShouldShowMore(false);
    if (!moreButton) {
      editor.adapter.focus();
      return;
    }
    const moreToolbar = document.querySelector(`[data-hook=${OverflownButtonsToolbar}]`);
    if (moreToolbar?.contains(document.activeElement)) {
      moreButton.focus();
      return;
    }
    editor.adapter.focus();
  };
  const onClickOutside = () => {
    if (modalService.getOpenModals().length > 0) {
      return;
    }
    if (shouldShowMore) {
      setShouldShowMore(false);
    }
  };
  const toggleMoreItems = () => setShouldShowMore(!shouldShowMore);
  return { closeToolbar, onClickOutside, toggleMoreItems, shouldShowMore };
};
export {
  useRicosDesktopToolbarActions
};
//# sourceMappingURL=use-ricos-desktop-toolbar-actions.js.map
