import { isCustomUpload } from "./../_shared/is-custom-upload.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 { createSettingsButton } from "./../_shared/plugin-toolbar/create-settings-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 { getNodeInSelection } from "./../_shared/resolvers/get-node-in-selection.js";
import { handleAudioUpload } from ".//handle-audio-upload.js";
import { FLOATING_PLUGIN_TOOLBAR } from "./../toolbars-v3/index.js";
import { AUDIO_BUTTONS, AUDIO_REPLACE_MODAL_ID, AUDIO_SETTINGS_MODAL_ID } from "./consts.js";
import { PLUGIN_TOOLBAR_AUDIO_SETTINGS_BUTTON } from "./data-hooks.js";
import { InsertModal } from "./modals/insert-modal.js";
import { AudioSettingsModal } from "./modals/settings-modal.js";
const isCustomAudioResolver = (content) => {
  if (Array.isArray(content) && content.length > 0) {
    return !!content[content.length - 1].attrs?.audio?.src?.id || !!isCustomUpload(content[content.length - 1].attrs?.audio?.src?.url);
  }
  return false;
};
const getToolbarButtons = (config, services) => {
  const { modals } = services;
  const settingsButton = createSettingsButton({
    modalId: AUDIO_SETTINGS_MODAL_ID,
    attributes: {
      visible: isCustomAudioResolver
    },
    dataHook: PLUGIN_TOOLBAR_AUDIO_SETTINGS_BUTTON,
    showLabel: true,
    command: ({ referenceElement, attributes: { selectedNode }, publicCommands }) => {
      const { uploadService, updateService } = services;
      modals?.togglePluginPanel({
        id: AUDIO_SETTINGS_MODAL_ID,
        Component: AudioSettingsModal,
        componentProps: {
          nodeId: selectedNode.attrs.id,
          onFileSelect: () => {
            if (uploadService && updateService) {
              handleAudioUpload({
                services,
                publicCommands,
                nodeId: selectedNode.attrs.id,
                type: "image",
                referenceElement
              });
            }
          }
        },
        isMobile: services.context.isMobile,
        positioning: {
          referenceElement: referenceElement?.closest(`[data-hook~=${FLOATING_PLUGIN_TOOLBAR}]`) ?? referenceElement,
          placement: "right-start"
        },
        focusReturnElement: referenceElement
      });
    }
  });
  const separator1 = createSeparator({
    visible: isCustomAudioResolver,
    selectedNode: getNodeInSelection
  });
  const sizeButton = createNodeSizeButton({
    services,
    modalId: AUDIO_BUTTONS.size,
    options: ["SMALL", "CONTENT"]
  });
  const alignmentButton = createNodeAlignmentButton({ services, modalId: AUDIO_BUTTONS.alignment });
  const replaceButton = createReplaceButton({
    modalId: AUDIO_REPLACE_MODAL_ID,
    command: ({ referenceElement, attributes: { selectedNode } }) => {
      const {
        audio: { src },
        id
      } = selectedNode.attrs;
      modals?.togglePluginPanel({
        id: AUDIO_REPLACE_MODAL_ID,
        Component: InsertModal,
        componentProps: {
          componentData: selectedNode.attrs,
          nodeId: id,
          embedType: src.url,
          modalId: AUDIO_REPLACE_MODAL_ID
        },
        isMobile: services.context.isMobile,
        positioning: {
          referenceElement,
          placement: "bottom"
        },
        mobileLayout: "drawer"
      });
    }
  });
  const separator2 = createSeparator();
  const deleteButton = createDeleteButton();
  if (services.context.environment === "wixel") {
    return [settingsButton, replaceButton, sizeButton, alignmentButton, deleteButton];
  }
  return [
    settingsButton,
    separator1,
    sizeButton,
    alignmentButton,
    replaceButton,
    separator2,
    deleteButton
  ];
};
export {
  getToolbarButtons
};
//# sourceMappingURL=get-toolbar-buttons.js.map
