"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_react = __toESM(require("react"));
var import_ricos_content = require("./../ricos-content/index.js");
var import_constants = require("./../_shared/link-modal/constants.js");
var import_toggle_link_modal = require("./../_shared/link-modal/toggle-link-modal.js");
var import_create_settings_button = require("./../_shared/plugin-toolbar/create-settings-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_anchor_data = require("./../_shared/resolvers/get-anchor-data.js");
var import_get_url_link_data = require("./../_shared/resolvers/get-url-link-data.js");
var import_is_always_visible = require("./../_shared/resolvers/is-always-visible.js");
var import_is_anchor_in_text = require("./../_shared/resolvers/is-anchor-in-text.js");
var import_is_link_in_text = require("./../_shared/resolvers/is-link-in-text.js");
var import_is_link_preview_enabled = require("./../_shared/resolvers/is-link-preview-enabled.js");
var import_data_hooks = require("./data-hooks.js");
var import_anchor_link_button = require("./toolbar/anchor-link-button.js");
var import_display_link_preview_button = require("./toolbar/display-link-preview-button.js");
var import_remove_link_button = require("./toolbar/remove-link-button.js");
const getToolbarButtons = (_config, services) => {
  const anchorLink = {
    id: "anchorLink",
    type: "toggle",
    dataHook: import_data_hooks.LINK_PLUGIN_SCROLL_TO_ANCHOR_BUTTON,
    attributes: {
      visible: import_is_anchor_in_text.isAnchorInText,
      selectedAnchorLinkData: import_get_anchor_data.getAnchorData
    },
    tooltip: null,
    icon: () => /* @__PURE__ */ import_react.default.createElement("span", { style: { textDecoration: "underline" } }, services.t("LinkTo_Toolbar_GoTo")),
    command: ({ tiptapEditor, attributes: { selectedAnchorLinkData } }) => {
      tiptapEditor.commands.scrollToAnchor(selectedAnchorLinkData);
    },
    renderer: (toolbarItem) => /* @__PURE__ */ import_react.default.createElement(import_anchor_link_button.AnchorLinkButton, { toolbarItem })
  };
  const urlLink = (0, import_create_url_link_button.createUrlLinkButton)({
    services,
    attributes: {
      visible: import_is_link_in_text.isLinkInText,
      selectedUrlLinkData: import_get_url_link_data.getUrlLinkData
    }
  });
  const displayLinkPreview = {
    id: "displayLinkPreview",
    type: "toggle",
    dataHook: import_data_hooks.LINK_PLUGIN_DISPLAY_AS_LINK_PREVIEW_BUTTON,
    tooltip: "LinkPanelContainer_DisplayAsLinkPreview",
    icon: import_wix_ui_icons_common.Newspaper,
    attributes: {
      visible: import_is_link_preview_enabled.isLinkPreviewEnabled
    },
    command: ({ tiptapEditor }) => {
      tiptapEditor.commands.createLinkPreview();
    },
    renderer: (toolbarItem) => /* @__PURE__ */ import_react.default.createElement(import_display_link_preview_button.DisplayLinkPreview, { toolbarItem })
  };
  const separator1 = (0, import_create_separator.createSeparator)({
    visible: import_is_always_visible.isAlwaysVisible
  });
  const settings = (0, import_create_settings_button.createSettingsButton)({
    modalId: import_constants.LINK_MODAL_ID,
    command: ({ publicCommands, referenceElement, modals }) => {
      (0, import_toggle_link_modal.toggleLinkModal)({
        initialValue: publicCommands.getLinkDataInSelection(),
        modalService: modals,
        onSave: (link) => {
          publicCommands.insertDecoration(link.anchor ? import_ricos_content.RICOS_ANCHOR_TYPE : import_ricos_content.RICOS_LINK_TYPE, link);
        },
        onUnlink: (link) => {
          publicCommands.deleteDecoration(link.anchor ? import_ricos_content.RICOS_ANCHOR_TYPE : import_ricos_content.RICOS_LINK_TYPE);
        },
        referenceElement,
        returnFocusToEditor: true,
        onClickOutside: {
          on: "pointerup",
          handler: (e) => {
            if (!referenceElement?.contains?.(e.target)) {
              modals.closeModal(import_constants.LINK_MODAL_ID);
              return;
            }
          }
        }
      });
    }
  });
  const separator2 = (0, import_create_separator.createSeparator)({
    visible: import_is_always_visible.isAlwaysVisible
  });
  const removeLink = {
    id: "removeLink",
    type: "toggle",
    dataHook: import_data_hooks.LINK_PLUGIN_REMOVE_BUTTON,
    tooltip: "LinkPanelContainer_RemoveButton",
    icon: import_wix_ui_icons_common.Unlink,
    attributes: {
      visible: import_is_link_in_text.isLinkInText
    },
    command: ({ tiptapEditor }) => {
      tiptapEditor.chain().focus().unsetLink().run();
    },
    renderer: (toolbarItem) => /* @__PURE__ */ import_react.default.createElement(import_remove_link_button.RemoveLinkButton, { toolbarItem })
  };
  const removeAnchor = {
    id: "removeAnchor",
    type: "toggle",
    dataHook: import_data_hooks.LINK_PLUGIN_REMOVE_BUTTON,
    tooltip: "LinkPanelContainer_RemoveButton",
    icon: import_wix_ui_icons_common.Unlink,
    attributes: {
      visible: import_is_anchor_in_text.isAnchorInText
    },
    command: ({ tiptapEditor }) => {
      tiptapEditor.chain().focus().unsetAnchor().run();
    },
    renderer: (toolbarItem) => /* @__PURE__ */ import_react.default.createElement(import_remove_link_button.RemoveLinkButton, { toolbarItem })
  };
  if (services.context.environment === "wixel") {
    return [anchorLink, urlLink, settings, displayLinkPreview, removeLink, removeAnchor];
  }
  return [
    anchorLink,
    urlLink,
    separator1,
    displayLinkPreview,
    settings,
    separator2,
    removeLink,
    removeAnchor
  ];
};
//# sourceMappingURL=get-toolbar-buttons.js.map
