"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_v1 = require("./../ricos-schema/legacy/wix/rich_content/v1/index.js");
var import_create_plugin_toolbar_button = require("./../_shared/create-plugin-toolbar-button.js");
var import_data_hooks = require("./../_shared/data-hooks.js");
var import_consts = require("./../_shared/node-alignment-dropdown/consts.js");
var import_node_alignment_dropdown = require("./../_shared/node-alignment-dropdown/node-alignment-dropdown.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_alignment = require("./../_shared/resolvers/get-node-alignment.js");
var import_get_node_in_selection = require("./../_shared/resolvers/get-node-in-selection.js");
var import_is_visible_only_on_desktop = require("./../_shared/resolvers/is-visible-only-on-desktop.js");
var import_const = require("./const.js");
var import_data_hooks2 = require("./data-hooks.js");
var import_divider_alignment_button = require("./toolbar/buttons/divider-alignment-button.js");
var import_divider_buttons_data = require("./toolbar/buttons/divider-buttons-data.js");
var import_divider_size_button = require("./toolbar/buttons/divider-size-button.js");
var import_divider_style_button = require("./toolbar/buttons/divider-style-button.js");
var import_divider_size_panel = require("./toolbar/modals/divider-size-panel.js");
var import_line_style_panel = require("./toolbar/modals/line-style-panel.js");
const resolveDividerAttribute = (attribute) => (content) => {
  if (Array.isArray(content) && content.length > 0) {
    return content.find((node) => node.type.name === import_ricos_content.TIPTAP_DIVIDER_TYPE)?.attrs?.[attribute];
  }
  return void 0;
};
const getToolbarButtons = (_config, services) => {
  const {
    context: { isMobile }
  } = services;
  const styleButton = (0, import_create_plugin_toolbar_button.createPluginToolbarButton)({
    id: import_const.DIVIDER_BUTTONS.style,
    type: "dropdown",
    attributes: {
      nodeStyle: resolveDividerAttribute("lineStyle"),
      active: (_, { modals }) => Boolean(modals?.getModal(import_const.DIVIDER_BUTTONS.style))
    },
    dataHook: import_data_hooks2.PLUGIN_TOOLBAR_DIVIDER_STYLE_BUTTON,
    tooltip: "DividerPlugin_SelectType_Tooltip",
    getIcon: ({ attributes }) => {
      return import_divider_buttons_data.dividerStyleData.find(({ commandKey }) => commandKey === attributes.nodeStyle)?.icon || import_wix_ui_icons_common.Minus;
    },
    command: ({
      modals,
      referenceElement,
      getComponentProps,
      tiptapEditor,
      attributes,
      publicCommands
    }) => {
      const componentProps = getComponentProps?.({
        tiptapEditor,
        attributes,
        publicCommands,
        t: services.t,
        modals,
        languageDir: services.context.languageDir
      });
      if (!componentProps) {
        return;
      }
      modals.isModalOpen(import_const.DIVIDER_BUTTONS.style) ? modals.closeModal(import_const.DIVIDER_BUTTONS.style) : modals.openModal({
        id: import_const.DIVIDER_BUTTONS.style,
        Component: import_line_style_panel.LineStylePanel,
        componentProps,
        layout: isMobile ? "drawer" : "floating",
        positioning: { referenceElement, placement: "bottom" },
        onClickOutside: {
          on: "pointerup",
          handler: (e) => {
            if (!referenceElement?.contains?.(e.target)) {
              modals.closeModal(import_const.DIVIDER_BUTTONS.style);
              return;
            }
          }
        }
      });
    },
    Component: import_line_style_panel.LineStylePanel,
    getComponentProps: ({ tiptapEditor, modals, attributes, t }) => ({
      dropdownOptions: import_divider_buttons_data.dividerStyleData.map((option) => ({
        id: option.commandKey,
        dataHook: option.dataHook,
        label: t(option.text),
        icon: option.iconSmall,
        iconMobile: option.icon
      })),
      onSelect: (lineStyle) => {
        tiptapEditor.chain().focus().updateAttributes(import_ricos_content.TIPTAP_DIVIDER_TYPE, {
          lineStyle
        }).run();
      },
      selectedId: attributes.nodeStyle || "SINGLE",
      closeModal: () => modals.closeModal(import_const.DIVIDER_BUTTONS.style)
    }),
    renderer: (toolbarItem) => /* @__PURE__ */ import_react.default.createElement(import_divider_style_button.DividerStyleButton, { toolbarItem, id: import_const.DIVIDER_BUTTONS.style })
  });
  const sizeButton = (0, import_create_plugin_toolbar_button.createPluginToolbarButton)({
    id: import_const.DIVIDER_BUTTONS.size,
    type: "dropdown",
    attributes: {
      nodeSize: resolveDividerAttribute("width"),
      selectedNode: import_get_node_in_selection.getNodeInSelection,
      visible: (0, import_is_visible_only_on_desktop.isVisibleOnlyOnDesktop)(isMobile),
      active: (_, { modals }) => Boolean(modals?.getModal(import_const.DIVIDER_BUTTONS.size))
    },
    dataHook: import_data_hooks2.PLUGIN_TOOLBAR_DIVIDER_SIZE_BUTTON,
    getIcon: ({ attributes }) => {
      const getSelectedSize = () => attributes.nodeSize || import_v1.DividerData_Width.LARGE;
      const selectedSize = import_divider_buttons_data.dividerSizeData.find(
        ({ commandKey }) => commandKey === getSelectedSize()
      );
      return selectedSize?.icon || import_wix_ui_icons_common.DividerSizeMedium;
    },
    tooltip: "ButtonModal_Size_Section",
    command: ({
      modals,
      referenceElement,
      getComponentProps,
      tiptapEditor,
      attributes,
      publicCommands
    }) => {
      const componentProps = getComponentProps?.({
        tiptapEditor,
        attributes,
        publicCommands,
        t: services.t,
        modals,
        languageDir: services.context.languageDir
      });
      if (!componentProps) {
        return;
      }
      modals.isModalOpen(import_const.DIVIDER_BUTTONS.size) ? modals.closeModal(import_const.DIVIDER_BUTTONS.size) : modals.openModal({
        id: import_const.DIVIDER_BUTTONS.size,
        Component: import_divider_size_panel.DividerSizePanel,
        componentProps,
        layout: isMobile ? "drawer" : "floating",
        positioning: { referenceElement, placement: "bottom" },
        onClickOutside: {
          on: "pointerup",
          handler: (e) => {
            if (!referenceElement?.contains?.(e.target)) {
              modals.closeModal(import_const.DIVIDER_BUTTONS.size);
              return;
            }
          }
        }
      });
    },
    Component: import_divider_size_panel.DividerSizePanel,
    getComponentProps: ({ tiptapEditor, modals, attributes, t }) => ({
      dropdownOptions: import_divider_buttons_data.dividerSizeData.map((option) => ({
        id: option.commandKey,
        dataHook: option.dataHook,
        label: t(option.text),
        icon: option.iconSmall,
        iconMobile: option.icon
      })),
      onSelect: (value) => {
        const nodeContainerData = attributes.selectedNode.attrs?.containerData;
        const isFullWidth = value === import_v1.DividerData_Width.LARGE;
        const newAttributes = isFullWidth ? {
          width: value,
          alignment: import_v1.DividerData_Alignment.CENTER,
          containerData: {
            ...nodeContainerData,
            alignment: import_v1.DividerData_Alignment.CENTER
          }
        } : { width: value };
        tiptapEditor.chain().focus().updateAttributes(import_ricos_content.TIPTAP_DIVIDER_TYPE, newAttributes).run();
      },
      selectedId: attributes.nodeSize || import_v1.DividerData_Width.LARGE,
      closeModal: () => modals.closeModal(import_const.DIVIDER_BUTTONS.size)
    }),
    renderer: (toolbarItem) => /* @__PURE__ */ import_react.default.createElement(import_divider_size_button.DividerSizeButton, { toolbarItem })
  });
  const alignmentButton = (0, import_create_plugin_toolbar_button.createPluginToolbarButton)({
    id: import_const.DIVIDER_BUTTONS.alignment,
    type: "dropdown",
    attributes: {
      nodeAlignment: import_get_node_alignment.getNodeAlignment,
      selectedNode: import_get_node_in_selection.getNodeInSelection,
      visible: (0, import_is_visible_only_on_desktop.isVisibleOnlyOnDesktop)(isMobile),
      active: (_, { modals }) => Boolean(modals?.getModal(import_const.DIVIDER_BUTTONS.alignment))
    },
    dataHook: import_data_hooks.PLUGIN_TOOLBAR_ALIGNMENT_BUTTON,
    tooltip: "TextAlignmentButton_Tooltip",
    getIcon: ({ services: services2, attributes }) => {
      const selectedAlignment = attributes.nodeAlignment || getDefaultAlignment(services2.context.languageDir);
      const SelectedAlignmentIcon = import_divider_buttons_data.alignmentMap[selectedAlignment];
      return SelectedAlignmentIcon;
    },
    Component: import_node_alignment_dropdown.NodeAlignmentDropdown,
    getComponentProps: ({ tiptapEditor, modals, attributes, t, languageDir }) => {
      return {
        closeModal: () => modals.closeModal(import_const.DIVIDER_BUTTONS.alignment),
        onSelect: (alignment) => {
          const nodeContainerData = attributes.selectedNode.attrs?.containerData;
          tiptapEditor.chain().focus().updateAttributes(import_ricos_content.TIPTAP_DIVIDER_TYPE, {
            alignment,
            containerData: { ...nodeContainerData, alignment }
          }).run();
        },
        selectedId: attributes.nodeAlignment || getDefaultAlignment(languageDir),
        options: Object.values(import_consts.NODE_ALIGNMENT_BUTTONS).map((option) => ({
          type: option.type,
          id: option.commandKey,
          dataHook: option.dataHook,
          label: t(option.text),
          icon: option.iconSmall,
          iconMobile: option.icon
        }))
      };
    },
    command: ({
      tiptapEditor,
      modals,
      referenceElement,
      attributes,
      getComponentProps,
      publicCommands
    }) => {
      const componentProps = getComponentProps?.({
        tiptapEditor,
        attributes,
        publicCommands,
        t: services.t,
        modals,
        languageDir: services.context.languageDir
      });
      if (!componentProps) {
        return;
      }
      modals.isModalOpen(import_const.DIVIDER_BUTTONS.alignment) ? modals.closeModal(import_const.DIVIDER_BUTTONS.alignment) : modals.openModal({
        id: import_const.DIVIDER_BUTTONS.alignment,
        Component: import_node_alignment_dropdown.NodeAlignmentDropdown,
        componentProps,
        layout: isMobile ? "drawer" : "floating",
        positioning: { referenceElement, placement: "bottom" },
        onClickOutside: {
          on: "pointerup",
          handler: (e) => {
            if (!referenceElement?.contains?.(e.target)) {
              modals.closeModal(import_const.DIVIDER_BUTTONS.alignment);
              return;
            }
          }
        }
      });
    },
    renderer: (toolbarItem) => /* @__PURE__ */ import_react.default.createElement(import_divider_alignment_button.DividerAlignmentButton, { id: import_const.DIVIDER_BUTTONS.alignment, toolbarItem })
  });
  const separator = (0, import_create_separator.createSeparator)();
  const deleteButton = (0, import_create_delete_button.createDeleteButton)();
  if (services.context.environment === "wixel") {
    return [styleButton, sizeButton, alignmentButton, deleteButton];
  }
  return [styleButton, sizeButton, alignmentButton, separator, deleteButton];
};
const getDefaultAlignment = (langDir) => {
  return langDir === "rtl" ? "RIGHT" : "LEFT";
};
//# sourceMappingURL=get-toolbar-buttons.js.map
