"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 plugin_cell_exports = {};
__export(plugin_cell_exports, {
  pluginCell: () => pluginCell
});
module.exports = __toCommonJS(plugin_cell_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_ricos_context = require("./../../ricos-context/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_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_is_always_visible = require("./../../_shared/resolvers/is-always-visible.js");
var import_toolbar_button = require("./../../_shared/toolbar-button/toolbar-button.js");
var import_state = require("./../../tiptap/pm/state.js");
var import_cell_converter = require("./cell-converter.js");
var import_cell_extension = require("./cell-extension.js");
var import_data_hooks = require("./data-hooks.js");
var import_shared = require("./shared.js");
var import_add_cell_dropdown_button = require("./toolbar-buttons/add-cell-dropdown-button.js");
const pluginCell = (config = { showInQuickActions: false, showInToolbars: false }) => ({
  type: import_ricos_content.TIPTAP_LAYOUT_CELL_TYPE,
  config,
  pmMarkConverters: [],
  pmNodeConverters: [import_cell_converter.cellConverter],
  tiptapExtensions: [import_cell_extension.cellExtension],
  toolbar: {
    names: [import_ricos_types.RicosPluginToolbarNames.LAYOUT_CELL],
    resolveReferenceElement: (tiptapEditor) => (0, import_shared.getToolbarReferenceElement)(tiptapEditor),
    getButtons: (_, services) => services.context.isMobile ? [] : config.showInQuickActions || config.showInToolbars ? [
      {
        id: "layoutCellAddCellDropdown",
        type: "toggle",
        dataHook: import_data_hooks.LAYOUT_CELL_TOOLBAR_ADD_CELL_DROPDOWN_BUTTON,
        tooltip: "Layouts_AddCell_Tooltip",
        icon: import_wix_ui_icons_common.Add,
        command: ({ position, tiptapEditor, attributes: { selectedNode } }) => {
          if (position === "left") {
            tiptapEditor.commands.addCellLeft(selectedNode.attrs.id);
          } else {
            tiptapEditor.commands.addCellRight(selectedNode.attrs.id);
          }
        },
        attributes: {
          selectedNode: import_get_node_in_selection.getNodeInSelection,
          alwaysVisible: import_is_always_visible.isAlwaysVisible,
          canAddLeftCell: (_2, __, editor) => {
            const selection = editor?.state.selection;
            if (editor && selection instanceof import_state.NodeSelection) {
              const id = selection.node?.attrs.id;
              return editor.can().addCellLeft(id);
            }
            return false;
          },
          canAddRightCell: (_2, __, editor) => {
            const selection = editor?.state.selection;
            if (editor && selection instanceof import_state.NodeSelection) {
              const id = selection.node?.attrs.id;
              return editor.can().addCellRight(id);
            }
            return false;
          },
          disabled: (_2, __, editor) => {
            const selection = editor?.state.selection;
            if (editor && selection instanceof import_state.NodeSelection) {
              const id = selection.node?.attrs.id;
              return !editor.can().addCellLeft(id) && !editor.can().addCellRight(id);
            }
            return true;
          }
        },
        renderer: (toolbarItem) => /* @__PURE__ */ import_react.default.createElement(
          import_add_cell_dropdown_button.AddCellDropdownButton,
          {
            toolbarItem,
            attributes: toolbarItem.attributes
          }
        )
      },
      {
        id: "moveCellLeft",
        type: "toggle",
        dataHook: import_data_hooks.LAYOUT_CELL_TOOLBAR_MOVE_LEFT_BUTTON,
        tooltip: "Layouts_CellMoveLeft_Tooltip",
        icon: import_wix_ui_icons_common.ArrowLeft,
        attributes: {
          alwaysVisible: import_is_always_visible.isAlwaysVisible,
          disabled: (_2, __, editor) => {
            const selection = editor?.state.selection;
            if (editor && selection instanceof import_state.NodeSelection) {
              const id = selection.node?.attrs.id;
              return !editor.can().moveCellLeft(id);
            }
            return true;
          },
          selectedNode: import_get_node_in_selection.getNodeInSelection
        },
        command: ({ tiptapEditor, attributes }) => {
          tiptapEditor.commands.moveCellLeft(attributes.selectedNode.attrs.id);
        },
        renderer: (toolbarItem) => /* @__PURE__ */ import_react.default.createElement(MoveCellLeftButton, { toolbarItem })
      },
      {
        id: "moveCellRight",
        type: "toggle",
        dataHook: import_data_hooks.LAYOUT_CELL_TOOLBAR_MOVE_RIGHT_BUTTON,
        tooltip: "Layouts_CellMoveRight_Tooltip",
        icon: import_wix_ui_icons_common.ArrowRight,
        attributes: {
          selectedNode: import_get_node_in_selection.getNodeInSelection,
          alwaysVisible: import_is_always_visible.isAlwaysVisible,
          disabled: (_2, __, editor) => {
            const selection = editor?.state.selection;
            if (editor && selection instanceof import_state.NodeSelection) {
              const id = selection.node?.attrs.id;
              return !editor.can().moveCellRight(id);
            }
            return true;
          }
        },
        command: ({ tiptapEditor, attributes }) => {
          tiptapEditor.commands.moveCellRight(attributes.selectedNode.attrs.id);
        },
        renderer: (toolbarItem) => /* @__PURE__ */ import_react.default.createElement(MoveCellRightButton, { toolbarItem })
      },
      (0, import_create_separator.createSeparator)(),
      (0, import_create_delete_button.createDeleteButton)({
        tooltip: "Layouts_CellDelete_Tooltip",
        attributes: {
          selectedNode: import_get_node_in_selection.getNodeInSelection
        },
        command: ({ tiptapEditor, attributes }) => {
          tiptapEditor.commands.deleteCell(attributes.selectedNode.attrs.id);
        }
      })
    ] : []
  }
});
const MoveCellLeftButton = ({ toolbarItem }) => {
  const { t } = (0, import_react.useContext)(import_ricos_context.RicosContext) || {};
  return /* @__PURE__ */ import_react.default.createElement(
    import_toolbar_button.ToolbarButton,
    {
      prefix: import_wix_ui_icons_common.ArrowLeftSmall,
      onClick: () => {
        toolbarItem.tiptapEditor.commands.moveCellLeft(
          toolbarItem.attributes.selectedNode.attrs.id
        );
      },
      dataHook: import_data_hooks.LAYOUT_CELL_TOOLBAR_MOVE_LEFT_BUTTON,
      tooltip: t("Layouts_CellMoveLeft_Tooltip"),
      tabIndex: toolbarItem.presentation.tabIndex
    }
  );
};
const MoveCellRightButton = ({ toolbarItem }) => {
  const { t } = (0, import_react.useContext)(import_ricos_context.RicosContext) || {};
  return /* @__PURE__ */ import_react.default.createElement(
    import_toolbar_button.ToolbarButton,
    {
      prefix: import_wix_ui_icons_common.ArrowRightSmall,
      onClick: () => {
        toolbarItem.tiptapEditor.commands.moveCellRight(
          toolbarItem.attributes.selectedNode.attrs.id
        );
      },
      dataHook: import_data_hooks.LAYOUT_CELL_TOOLBAR_MOVE_RIGHT_BUTTON,
      tooltip: t("Layouts_CellMoveRight_Tooltip"),
      tabIndex: toolbarItem.presentation.tabIndex
    }
  );
};
//# sourceMappingURL=plugin-cell.js.map
