"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 text_align_exports = {};
__export(text_align_exports, {
  pluginTextAlignment: () => pluginTextAlignment
});
module.exports = __toCommonJS(text_align_exports);
var import_wix_ui_icons_common = require("@wix/wix-ui-icons-common");
var import_react = __toESM(require("react"));
var import_ricos_types = require("./../../ricos-types/index.js");
var import_create_text_button = require("./../../_shared/create-text-button.js");
var import_get_alignment_in_selection = require("./../../_shared/resolvers/get-alignment-in-selection.js");
var import_is_always_visible = require("./../../_shared/resolvers/is-always-visible.js");
var import_is_node_selected = require("./../../_shared/resolvers/is-node-selected.js");
var import_is_text_aligned_center = require("./../../_shared/resolvers/is-text-aligned-center.js");
var import_is_text_aligned_justify = require("./../../_shared/resolvers/is-text-aligned-justify.js");
var import_is_text_aligned_left = require("./../../_shared/resolvers/is-text-aligned-left.js");
var import_is_text_aligned_right = require("./../../_shared/resolvers/is-text-aligned-right.js");
var import_alignment_button = require("./../../toolbars-v3/components/buttons/AlignmentButton/alignment-button.js");
var import_consts = require("./dropdown/consts.js");
var import_data_hooks = require("./dropdown/data-hooks.js");
var import_text_alignment_dropdown_lazy = __toESM(require("./dropdown/text-alignment-dropdown-lazy.js"));
var import_extension = require("./extension.js");
const FORMATTING_ALIGNMENT_MODAL_ID = "TextAlignment.modal";
const getAlignmentButtonPresentation = (alignmentProps) => ({
  dataHook: alignmentProps.dataHook,
  tooltip: alignmentProps.tooltip,
  icon: alignmentProps.icon
});
const pluginTextAlignment = {
  type: "TEXT_ALIGNMENT",
  config: {},
  tiptapExtensions: [import_extension.textAlign],
  shortcuts: [
    (0, import_ricos_types.createShortcut)({
      name: "TextAlignment.LEFT",
      description: "ShortcutsSheet_Formatting_AlignLeft",
      keys: { macOs: "Meta+Shift+L", windows: "Ctrl+Shift+L" },
      command({ publicCommands }) {
        publicCommands.setTextAlignment("left");
        return "continue";
      },
      group: "ShortcutsSheet_Section_Formatting",
      enabled: true,
      showInShortcutSheet: true
    }),
    (0, import_ricos_types.createShortcut)({
      name: "TextAlignment.CENTER",
      description: "ShortcutsSheet_Formatting_AlignCenter",
      keys: { macOs: "Meta+Shift+E", windows: "Ctrl+Shift+E" },
      command({ publicCommands }) {
        publicCommands.setTextAlignment("center");
        return "continue";
      },
      group: "ShortcutsSheet_Section_Formatting",
      enabled: true,
      showInShortcutSheet: true
    }),
    (0, import_ricos_types.createShortcut)({
      name: "TextAlignment.RIGHT",
      description: "ShortcutsSheet_Formatting_AlignRight",
      keys: { macOs: "Meta+Shift+R", windows: "Ctrl+Shift+R" },
      command({ publicCommands }) {
        publicCommands.setTextAlignment("right");
        return "continue";
      },
      group: "ShortcutsSheet_Section_Formatting",
      enabled: true,
      showInShortcutSheet: true
    }),
    (0, import_ricos_types.createShortcut)({
      name: "TextAlignment.JUSTIFY",
      description: "ShortcutsSheet_Formatting_Justify",
      keys: { macOs: "Meta+Shift+J", windows: "Ctrl+Shift+J" },
      command({ publicCommands }) {
        publicCommands.setTextAlignment("justify");
        return "continue";
      },
      group: "ShortcutsSheet_Section_Formatting",
      enabled: true,
      showInShortcutSheet: true
    })
  ],
  textButtons: [
    (0, import_create_text_button.createTextButton)({
      id: "TextAlignment.ALIGNMENT",
      type: "dropdown",
      presentation: {
        id: FORMATTING_ALIGNMENT_MODAL_ID,
        dataHook: import_data_hooks.TEXT_ALIGNMENT_DROPDOWN_BUTTON,
        tooltip: "AlignTextDropdownButton_Tooltip",
        getIcon: ({ publicCommands }) => {
          const currentAlignment = publicCommands?.getTextAlignment() || "left";
          return import_consts.ALIGNMENT_BUTTON_CONFIGS[currentAlignment]?.icon || import_wix_ui_icons_common.TextAlignLeftLight;
        },
        renderer: (toolbarItem) => /* @__PURE__ */ import_react.default.createElement(import_alignment_button.AlignmentButton, { toolbarItem }),
        Component: import_text_alignment_dropdown_lazy.default,
        getComponentProps: ({ publicCommands, t, modals }) => {
          return {
            dropdownOptions: Object.values(import_consts.ALIGNMENT_BUTTON_CONFIGS).map((item) => ({
              id: item.commandKey,
              dataHook: item.dataHook,
              label: t(item.text),
              icon: item.icon,
              iconMobile: item.iconMobile
            })),
            onSelect: (value) => {
              publicCommands.setTextAlignment(value);
            },
            selectedId: publicCommands.getTextAlignment() || "left",
            closeModal: () => {
              modals.closeModal(FORMATTING_ALIGNMENT_MODAL_ID);
            }
          };
        }
      },
      command: ({ modalService: modals, referenceElement, isMobile, componentProps }) => () => {
        if (!componentProps) {
          return false;
        }
        modals.isModalOpen(FORMATTING_ALIGNMENT_MODAL_ID) ? modals.closeModal(FORMATTING_ALIGNMENT_MODAL_ID) : modals.openModal({
          id: FORMATTING_ALIGNMENT_MODAL_ID,
          Component: import_text_alignment_dropdown_lazy.default,
          componentProps,
          positioning: {
            placement: "bottom",
            referenceElement
          },
          layout: isMobile ? "drawer" : referenceElement ? "floating" : "dialog",
          returnFocusToEditor: true
        });
        return true;
      },
      attributes: {
        visible: import_is_always_visible.isAlwaysVisible,
        selectedAlignment: import_get_alignment_in_selection.getAlignmentInSelection,
        disabled: import_is_node_selected.isNodeSelected
      }
    }),
    {
      id: "TextAlignment.LEFT",
      type: "toggle",
      presentation: getAlignmentButtonPresentation(import_consts.ALIGNMENT_BUTTON_CONFIGS.left),
      attributes: {
        visible: import_is_always_visible.isAlwaysVisible,
        active: import_is_text_aligned_left.isTextAlignedLeft,
        disabled: import_is_node_selected.isNodeSelected
      },
      command: ({ publicCommands }) => () => {
        publicCommands.setTextAlignment("left");
        return true;
      }
    },
    {
      id: "TextAlignment.CENTER",
      type: "toggle",
      presentation: getAlignmentButtonPresentation(import_consts.ALIGNMENT_BUTTON_CONFIGS.center),
      attributes: {
        visible: import_is_always_visible.isAlwaysVisible,
        active: import_is_text_aligned_center.isTextAlignedCenter,
        disabled: import_is_node_selected.isNodeSelected
      },
      command: ({ publicCommands }) => () => {
        publicCommands.setTextAlignment("center");
        return true;
      }
    },
    {
      id: "TextAlignment.RIGHT",
      type: "toggle",
      presentation: getAlignmentButtonPresentation(import_consts.ALIGNMENT_BUTTON_CONFIGS.right),
      attributes: {
        visible: import_is_always_visible.isAlwaysVisible,
        active: import_is_text_aligned_right.isTextAlignedRight,
        disabled: import_is_node_selected.isNodeSelected
      },
      command: ({ publicCommands }) => () => {
        publicCommands.setTextAlignment("right");
        return true;
      }
    },
    {
      id: "TextAlignment.JUSTIFY",
      type: "toggle",
      presentation: getAlignmentButtonPresentation(import_consts.ALIGNMENT_BUTTON_CONFIGS.justify),
      attributes: {
        visible: import_is_always_visible.isAlwaysVisible,
        active: import_is_text_aligned_justify.isTextAlignedJustify,
        disabled: import_is_node_selected.isNodeSelected
      },
      command: ({ publicCommands }) => () => {
        publicCommands.setTextAlignment("justify");
        return true;
      }
    }
  ]
};
//# sourceMappingURL=text-align.js.map
