"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var get_toolbar_buttons_exports = {};
__export(get_toolbar_buttons_exports, {
  getToolbarButtons: () => getToolbarButtons
});
module.exports = __toCommonJS(get_toolbar_buttons_exports);
var import_is_custom_upload = require("./../_shared/is-custom-upload.js");
var import_create_delete_button = require("./../_shared/plugin-toolbar/create-delete-button.js");
var import_create_node_alignment_button = require("./../_shared/plugin-toolbar/create-node-alignment-button.js");
var import_create_replace_button = require("./../_shared/plugin-toolbar/create-replace-button.js");
var import_create_settings_button = require("./../_shared/plugin-toolbar/create-settings-button.js");
var import_create_node_size_button = require("./../_shared/plugin-toolbar/node-size-button/create-node-size-button.js");
var import_create_separator = require("./../_shared/plugin-toolbar/separator/create-separator.js");
var import_get_node_in_selection = require("./../_shared/resolvers/get-node-in-selection.js");
var import_handle_audio_upload = require(".//handle-audio-upload.js");
var import_toolbars_v3 = require("./../toolbars-v3/index.js");
var import_consts = require("./consts.js");
var import_data_hooks = require("./data-hooks.js");
var import_insert_modal = require("./modals/insert-modal.js");
var import_settings_modal = require("./modals/settings-modal.js");
const isCustomAudioResolver = (content) => {
  if (Array.isArray(content) && content.length > 0) {
    return !!content[content.length - 1].attrs?.audio?.src?.id || !!(0, import_is_custom_upload.isCustomUpload)(content[content.length - 1].attrs?.audio?.src?.url);
  }
  return false;
};
const getToolbarButtons = (config, services) => {
  const { modals } = services;
  const settingsButton = (0, import_create_settings_button.createSettingsButton)({
    modalId: import_consts.AUDIO_SETTINGS_MODAL_ID,
    attributes: {
      visible: isCustomAudioResolver
    },
    dataHook: import_data_hooks.PLUGIN_TOOLBAR_AUDIO_SETTINGS_BUTTON,
    showLabel: true,
    command: ({ referenceElement, attributes: { selectedNode }, publicCommands }) => {
      const { uploadService, updateService } = services;
      modals?.togglePluginPanel({
        id: import_consts.AUDIO_SETTINGS_MODAL_ID,
        Component: import_settings_modal.AudioSettingsModal,
        componentProps: {
          nodeId: selectedNode.attrs.id,
          onFileSelect: () => {
            if (uploadService && updateService) {
              (0, import_handle_audio_upload.handleAudioUpload)({
                services,
                publicCommands,
                nodeId: selectedNode.attrs.id,
                type: "image",
                referenceElement
              });
            }
          }
        },
        isMobile: services.context.isMobile,
        positioning: {
          referenceElement: referenceElement?.closest(`[data-hook~=${import_toolbars_v3.FLOATING_PLUGIN_TOOLBAR}]`) ?? referenceElement,
          placement: "right-start"
        },
        focusReturnElement: referenceElement
      });
    }
  });
  const separator1 = (0, import_create_separator.createSeparator)({
    visible: isCustomAudioResolver,
    selectedNode: import_get_node_in_selection.getNodeInSelection
  });
  const sizeButton = (0, import_create_node_size_button.createNodeSizeButton)({
    services,
    modalId: import_consts.AUDIO_BUTTONS.size,
    options: ["SMALL", "CONTENT"]
  });
  const alignmentButton = (0, import_create_node_alignment_button.createNodeAlignmentButton)({ services, modalId: import_consts.AUDIO_BUTTONS.alignment });
  const replaceButton = (0, import_create_replace_button.createReplaceButton)({
    modalId: import_consts.AUDIO_REPLACE_MODAL_ID,
    command: ({ referenceElement, attributes: { selectedNode } }) => {
      const {
        audio: { src },
        id
      } = selectedNode.attrs;
      modals?.togglePluginPanel({
        id: import_consts.AUDIO_REPLACE_MODAL_ID,
        Component: import_insert_modal.InsertModal,
        componentProps: {
          componentData: selectedNode.attrs,
          nodeId: id,
          embedType: src.url,
          modalId: import_consts.AUDIO_REPLACE_MODAL_ID
        },
        isMobile: services.context.isMobile,
        positioning: {
          referenceElement,
          placement: "bottom"
        },
        mobileLayout: "drawer"
      });
    }
  });
  const separator2 = (0, import_create_separator.createSeparator)();
  const deleteButton = (0, import_create_delete_button.createDeleteButton)();
  if (services.context.environment === "wixel") {
    return [settingsButton, replaceButton, sizeButton, alignmentButton, deleteButton];
  }
  return [
    settingsButton,
    separator1,
    sizeButton,
    alignmentButton,
    replaceButton,
    separator2,
    deleteButton
  ];
};
//# sourceMappingURL=get-toolbar-buttons.js.map
