import { TextAlignLeftLight } from "@wix/wix-ui-icons-common";
import React from "react";
import { createShortcut } from "./../../ricos-types/index.js";
import { createTextButton } from "./../../_shared/create-text-button.js";
import { getAlignmentInSelection } from "./../../_shared/resolvers/get-alignment-in-selection.js";
import { isAlwaysVisible } from "./../../_shared/resolvers/is-always-visible.js";
import { isNodeSelected } from "./../../_shared/resolvers/is-node-selected.js";
import { isTextAlignedCenter } from "./../../_shared/resolvers/is-text-aligned-center.js";
import { isTextAlignedJustify } from "./../../_shared/resolvers/is-text-aligned-justify.js";
import { isTextAlignedLeft } from "./../../_shared/resolvers/is-text-aligned-left.js";
import { isTextAlignedRight } from "./../../_shared/resolvers/is-text-aligned-right.js";
import { AlignmentButton } from "./../../toolbars-v3/components/buttons/AlignmentButton/alignment-button.js";
import { ALIGNMENT_BUTTON_CONFIGS } from "./dropdown/consts.js";
import { TEXT_ALIGNMENT_DROPDOWN_BUTTON } from "./dropdown/data-hooks.js";
import AlignmentPanelComponent from "./dropdown/text-alignment-dropdown-lazy.js";
import { textAlign } from "./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: [textAlign],
  shortcuts: [
    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
    }),
    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
    }),
    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
    }),
    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: [
    createTextButton({
      id: "TextAlignment.ALIGNMENT",
      type: "dropdown",
      presentation: {
        id: FORMATTING_ALIGNMENT_MODAL_ID,
        dataHook: TEXT_ALIGNMENT_DROPDOWN_BUTTON,
        tooltip: "AlignTextDropdownButton_Tooltip",
        getIcon: ({ publicCommands }) => {
          const currentAlignment = publicCommands?.getTextAlignment() || "left";
          return ALIGNMENT_BUTTON_CONFIGS[currentAlignment]?.icon || TextAlignLeftLight;
        },
        renderer: (toolbarItem) => /* @__PURE__ */ React.createElement(AlignmentButton, { toolbarItem }),
        Component: AlignmentPanelComponent,
        getComponentProps: ({ publicCommands, t, modals }) => {
          return {
            dropdownOptions: Object.values(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: AlignmentPanelComponent,
          componentProps,
          positioning: {
            placement: "bottom",
            referenceElement
          },
          layout: isMobile ? "drawer" : referenceElement ? "floating" : "dialog",
          returnFocusToEditor: true
        });
        return true;
      },
      attributes: {
        visible: isAlwaysVisible,
        selectedAlignment: getAlignmentInSelection,
        disabled: isNodeSelected
      }
    }),
    {
      id: "TextAlignment.LEFT",
      type: "toggle",
      presentation: getAlignmentButtonPresentation(ALIGNMENT_BUTTON_CONFIGS.left),
      attributes: {
        visible: isAlwaysVisible,
        active: isTextAlignedLeft,
        disabled: isNodeSelected
      },
      command: ({ publicCommands }) => () => {
        publicCommands.setTextAlignment("left");
        return true;
      }
    },
    {
      id: "TextAlignment.CENTER",
      type: "toggle",
      presentation: getAlignmentButtonPresentation(ALIGNMENT_BUTTON_CONFIGS.center),
      attributes: {
        visible: isAlwaysVisible,
        active: isTextAlignedCenter,
        disabled: isNodeSelected
      },
      command: ({ publicCommands }) => () => {
        publicCommands.setTextAlignment("center");
        return true;
      }
    },
    {
      id: "TextAlignment.RIGHT",
      type: "toggle",
      presentation: getAlignmentButtonPresentation(ALIGNMENT_BUTTON_CONFIGS.right),
      attributes: {
        visible: isAlwaysVisible,
        active: isTextAlignedRight,
        disabled: isNodeSelected
      },
      command: ({ publicCommands }) => () => {
        publicCommands.setTextAlignment("right");
        return true;
      }
    },
    {
      id: "TextAlignment.JUSTIFY",
      type: "toggle",
      presentation: getAlignmentButtonPresentation(ALIGNMENT_BUTTON_CONFIGS.justify),
      attributes: {
        visible: isAlwaysVisible,
        active: isTextAlignedJustify,
        disabled: isNodeSelected
      },
      command: ({ publicCommands }) => () => {
        publicCommands.setTextAlignment("justify");
        return true;
      }
    }
  ]
};
export {
  pluginTextAlignment
};
//# sourceMappingURL=text-align.js.map
