import { TIPTAP_FIGURE_TYPE } from "./../ricos-content/consts.js";
import { createDeleteButton } from "./../_shared/plugin-toolbar/create-delete-button.js";
import { createNodeAlignmentButton } from "./../_shared/plugin-toolbar/create-node-alignment-button.js";
import { createReplaceButton } from "./../_shared/plugin-toolbar/create-replace-button.js";
import { createNodeSizeButton } from "./../_shared/plugin-toolbar/node-size-button/create-node-size-button.js";
import { createSeparator } from "./../_shared/plugin-toolbar/separator/create-separator.js";
import { isVisibleOnlyOnDesktop } from "./../_shared/resolvers/is-visible-only-on-desktop.js";
import { FLOATING_PLUGIN_TOOLBAR } from "./../toolbars-v3/index.js";
import { GIF_BUTTONS, gifModals } from "./constants.js";
import { GiphyInsertModal } from "./modals/insert-modal.js";
const getToolbarButtons = (config, services) => {
  const {
    context: { isMobile }
  } = services;
  const sizeButton = createNodeSizeButton({
    services,
    modalId: GIF_BUTTONS.size,
    options: ["SMALL", "CONTENT", "FULL_WIDTH", "ORIGINAL"]
  });
  const separator1 = createSeparator({
    visible: isVisibleOnlyOnDesktop(isMobile)
  });
  const alignmentButton = createNodeAlignmentButton({ services, modalId: GIF_BUTTONS.alignment });
  const separator2 = createSeparator({
    visible: isVisibleOnlyOnDesktop(isMobile)
  });
  const replaceButton = createReplaceButton({
    modalId: gifModals.replace,
    command: ({ referenceElement, attributes: { selectedNode } }) => {
      const { modals } = services;
      modals?.togglePluginPanel({
        id: gifModals.replace,
        Component: GiphyInsertModal,
        componentProps: {
          nodeId: selectedNode.attrs.id,
          modalId: gifModals.replace,
          getGiphyUrl: config?.getGiphyUrl
        },
        positioning: {
          referenceElement: referenceElement?.closest(`[data-hook~=${FLOATING_PLUGIN_TOOLBAR}]`) ?? referenceElement,
          placement: "right-start"
        },
        isMobile,
        focusReturnElement: referenceElement
      });
    }
  });
  const separator3 = createSeparator();
  const deleteButton = createDeleteButton({
    command: (data) => {
      const figures = data.tiptapEditor.$nodes(TIPTAP_FIGURE_TYPE);
      const selectedFigure = figures?.find((f) => {
        return f.firstChild?.node.attrs.id === data.attributes.selectedNode.attrs.id;
      });
      if (selectedFigure) {
        data.tiptapEditor.chain().focus().deleteNode(selectedFigure.attributes.id).run();
      }
    }
  });
  return [
    sizeButton,
    separator1,
    alignmentButton,
    separator2,
    replaceButton,
    separator3,
    deleteButton
  ];
};
export {
  getToolbarButtons
};
//# sourceMappingURL=get-toolbar-buttons.js.map
