"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
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 __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
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_wix_ui_icons_common = require("@wix/wix-ui-icons-common");
var import_lodash = __toESM(require("lodash"));
var import_react = __toESM(require("react"));
var import_ricos_content = require("./../ricos-content/index.js");
var import_ricos_types = require("./../ricos-types/index.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_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_create_url_link_button = require("./../_shared/plugin-toolbar/url-link-button/create-url-link-button.js");
var import_get_link_prieview_link_data = require("./../_shared/resolvers/get-link-prieview-link-data.js");
var import_get_node_in_selection = require("./../_shared/resolvers/get-node-in-selection.js");
var import_is_embed_in_selection = require("./../_shared/resolvers/is-embed-in-selection.js");
var import_is_link_in_link_preview = require("./../_shared/resolvers/is-link-in-link-preview.js");
var import_is_link_preview_in_selection = require("./../_shared/resolvers/is-link-preview-in-selection.js");
var import_ricos_toolbars = require("./../toolbars-v3/ricos-toolbars/index.js");
var import_consts = require("./consts.js");
var import_data_hooks = require("./data-hooks.js");
var import_settings_modal = require("./modals/settings-modal.js");
var import_disply_as_url_button = require("./toolbar/disply-as-url-button.js");
var import_unlink_button = require("./toolbar/unlink-button.js");
const isLinkPreviewSelectedResolver = (content) => {
  if (Array.isArray(content) && content.length > 0) {
    return content[0].type?.name === import_ricos_content.TIPTAP_LINK_PREVIEW_TYPE;
  }
  return false;
};
const getToolbarButtons = (config, services) => {
  const { modals } = services;
  const urlLinkButton = (0, import_create_url_link_button.createUrlLinkButton)({
    services,
    attributes: {
      selectedUrlLinkData: import_get_link_prieview_link_data.getLinkPreviewLinkData,
      visible: import_is_link_in_link_preview.isLinkInLinkPreview,
      selectedNode: import_get_node_in_selection.getNodeInSelection
    }
  });
  const separator1 = (0, import_create_separator.createSeparator)({
    visible: import_is_link_in_link_preview.isLinkInLinkPreview
  });
  const displayAsUrlButton = {
    id: `${import_ricos_types.Node_Type.LINK_PREVIEW}.replace`,
    type: "toggle",
    dataHook: import_data_hooks.PLUGIN_TOOLBAR_REPLACE_TO_LINK_BUTTON,
    icon: import_wix_ui_icons_common.Link,
    tooltip: "LinkPreview_RemovePreview_Tooltip",
    command: ({ tiptapEditor, attributes: { selectedNode } }) => {
      const link = selectedNode.type.name === import_ricos_content.TIPTAP_EMBED_TYPE ? selectedNode.attrs.src : selectedNode.attrs.link.url;
      tiptapEditor.chain().focus().setMeta("allowTextReplace", true).insertContent(link + " ").run();
    },
    attributes: {
      selectedNode: import_get_node_in_selection.getNodeInSelection
    },
    renderer: (toolbarItem) => /* @__PURE__ */ import_react.default.createElement(import_disply_as_url_button.DisplayAsUrlButton, { toolbarItem })
  };
  const sizeButton = (0, import_create_node_size_button.createNodeSizeButton)({
    services,
    modalId: `${import_ricos_types.Node_Type.LINK_PREVIEW}.size`,
    options: ["SMALL", "CONTENT", "FULL_WIDTH"]
  });
  const alignmentButton = (0, import_create_node_alignment_button.createNodeAlignmentButton)({
    services,
    modalId: `${import_ricos_types.Node_Type.LINK_PREVIEW}.alignment`
  });
  const settingsButton = (0, import_create_settings_button.createSettingsButton)({
    modalId: import_consts.linkPreviewModals.settings,
    command: ({ referenceElement, attributes: { selectedNode } }) => {
      const isModalOpen = modals.isModalOpen(import_consts.linkPreviewModals.settings);
      isModalOpen ? modals.closeModal(import_consts.linkPreviewModals.settings) : modals.togglePluginPanel({
        id: import_consts.linkPreviewModals.settings,
        Component: import_settings_modal.SettingsModal,
        componentProps: {
          referenceElement,
          nodeId: selectedNode.attrs.id,
          activeTab: "settings",
          config
        },
        positioning: {
          referenceElement: referenceElement?.closest(`[data-hook~=${import_ricos_toolbars.FLOATING_PLUGIN_TOOLBAR}]`) ?? referenceElement,
          placement: "right-start"
        },
        onClickOutside: {
          on: "pointerup",
          handler: import_lodash.default.noop
        },
        focusReturnElement: referenceElement,
        isMobile: services.context.isMobile
      });
    },
    attributes: { visible: isLinkPreviewSelectedResolver }
  });
  const separator2 = (0, import_create_separator.createSeparator)({
    visible: import_is_link_preview_in_selection.isLinkPreviewInSelection
  });
  const unlinkButton = {
    id: `${import_ricos_types.Node_Type.LINK_PREVIEW}.unlink`,
    type: "toggle",
    dataHook: import_data_hooks.PLUGIN_TOOLBAR_UNLINK_BUTTON,
    tooltip: "LinkPreview_Unlink_Tooltip",
    icon: import_wix_ui_icons_common.Unlink,
    command: ({ tiptapEditor, attributes: { selectedNode } }) => {
      const link = selectedNode.type.name === import_ricos_content.TIPTAP_EMBED_TYPE ? selectedNode.attrs.src : selectedNode.attrs.link.url;
      const { state } = tiptapEditor;
      const { selection } = state;
      const from = selection.from;
      tiptapEditor.chain().focus().setMeta("allowTextReplace", true).insertContent(link + " ").setTextSelection({ from, to: from + link.length + 1 }).run();
      tiptapEditor.chain().unsetLink().run();
    },
    attributes: {
      selectedNode: import_get_node_in_selection.getNodeInSelection,
      visible: import_is_link_preview_in_selection.isLinkPreviewInSelection
    },
    renderer: (toolbarItem) => /* @__PURE__ */ import_react.default.createElement(import_unlink_button.UnlinkButton, { toolbarItem })
  };
  const deleteButton = (0, import_create_delete_button.createDeleteButton)({
    attributes: { visible: import_is_embed_in_selection.isEmbedInSelection }
  });
  return [
    urlLinkButton,
    separator1,
    displayAsUrlButton,
    sizeButton,
    alignmentButton,
    settingsButton,
    separator2,
    unlinkButton,
    deleteButton
  ];
};
//# sourceMappingURL=get-toolbar-buttons.js.map
