import { posToDOMRect } from "./../../tiptap/index.js";
import { LINK_MODAL_ID } from "./constants.js";
import { LinkModal } from "./open-link-modal/link-modal.js";
const openLinkModal = ({
  editor,
  initialValue,
  modalService,
  onClickOutside,
  onSave,
  onSaveMultiple,
  onUnlink,
  placement,
  referenceElement: argReferenceElement,
  returnFocusToEditor,
  enabledLinkTypes
}) => {
  const referenceElement = argReferenceElement ? argReferenceElement : editor ? {
    getBoundingClientRect: () => posToDOMRect(
      editor.view,
      editor.view.state.selection.from,
      editor.view.state.selection.to
    )
  } : null;
  modalService.openModal({
    Component: LinkModal,
    componentProps: {
      initialValue,
      enabledLinkTypes,
      onClose: () => modalService.closeModal(LINK_MODAL_ID),
      onSaveMultiple,
      onSave,
      onUnlink
    },
    disableArrowNavigation: true,
    dragHandleSelector: "[data-drag-handler]",
    enableDrag: true,
    id: LINK_MODAL_ID,
    layout: {
      desktop: referenceElement ? "floating" : "dialog",
      //TODO: get layout value directly
      mobile: "fullscreen"
    },
    noPadding: true,
    ...referenceElement && {
      positioning: { placement: placement ?? "bottom", referenceElement }
    },
    withTransition: true,
    ...onClickOutside ? { onClickOutside } : {},
    returnFocusToEditor
  });
};
export {
  openLinkModal
};
//# sourceMappingURL=open-link-modal.js.map
