"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 create_orientation_dropdown_button_exports = {};
__export(create_orientation_dropdown_button_exports, {
  createOrientationDropdownButton: () => createOrientationDropdownButton
});
module.exports = __toCommonJS(create_orientation_dropdown_button_exports);
var import_react = __toESM(require("react"));
var import_ricos_context = require("./../../ricos-context/index.js");
var import_create_plugin_toolbar_button = require("./../../_shared/create-plugin-toolbar-button.js");
var import_dropdown_modal = require("./../../_shared/dropdown-modal/dropdown-modal.js");
var import_list_item_select = require("./../../_shared/list-item-select/list-item-select.js");
var import_data_hooks = require("../data-hooks.js");
var import_orientation_dropdown_button = require("./buttons/orientation-dropdown-button.js");
var import_orientation_options = require("./orientation-options.js");
var import_resolvers = require("./resolvers.js");
const createOrientationDropdownButton = ({ services }) => (0, import_create_plugin_toolbar_button.createPluginToolbarButton)({
  id: "smartBlockOrientation",
  type: "dropdown",
  getIcon: ({ attributes }) => import_orientation_options.ORIENTATION_OPTIONS[(0, import_orientation_options.getSelectedOrientation)(attributes.selectedNode?.attrs?.orientation)].icon,
  tooltip: "SmartBlock_Toolbar_Orientation_Tooltip",
  dataHook: import_data_hooks.DATA_HOOKS.DIRECTION_DROPDOWN_BUTTON,
  attributes: {
    selectedNode: import_resolvers.getSmartBlockNode,
    visible: import_resolvers.isLayoutSelectedAndOrientationVariant,
    active: (_, { modals }) => Boolean(modals?.getModal(import_orientation_options.SMART_BLOCK_ORIENTATION_DROPDOWN_ID))
  },
  renderer: (toolbarItem) => /* @__PURE__ */ import_react.default.createElement(import_orientation_dropdown_button.OrientationDropdownButton, { toolbarItem }),
  Component: OrientationDropdown,
  command: (props) => {
    const {
      modals,
      referenceElement,
      getComponentProps,
      tiptapEditor,
      attributes,
      publicCommands
    } = props;
    const componentProps = getComponentProps?.({
      tiptapEditor,
      attributes,
      publicCommands,
      t: services.t,
      modals,
      languageDir: services.context.languageDir
    });
    if (!componentProps) {
      return;
    }
    modals.isModalOpen(import_orientation_options.SMART_BLOCK_ORIENTATION_DROPDOWN_ID) ? modals.closeModal(import_orientation_options.SMART_BLOCK_ORIENTATION_DROPDOWN_ID) : modals.openModal({
      id: import_orientation_options.SMART_BLOCK_ORIENTATION_DROPDOWN_ID,
      Component: OrientationDropdown,
      componentProps,
      layout: services.context.isMobile ? "drawer" : "floating",
      positioning: { referenceElement, placement: "bottom" },
      type: "exclusive"
    });
  },
  getComponentProps: ({ tiptapEditor, attributes, t, modals }) => ({
    dropdownOptions: Object.entries(import_orientation_options.ORIENTATION_OPTIONS).map(([id, option]) => ({
      id,
      dataHook: option.dataHook,
      label: t(option.labelKey),
      icon: option.icon,
      iconMobile: option.iconMobile
    })),
    onSelect: (orientation) => {
      tiptapEditor.commands.setSmartBlockOrientation(orientation);
      modals.closeModal(import_orientation_options.SMART_BLOCK_ORIENTATION_DROPDOWN_ID);
    },
    selectedId: (0, import_orientation_options.getSelectedOrientation)(attributes.selectedNode?.attrs?.orientation),
    closeModal: () => modals.closeModal(import_orientation_options.SMART_BLOCK_ORIENTATION_DROPDOWN_ID)
  })
});
const OrientationDropdown = ({
  dropdownOptions,
  onSelect,
  selectedId,
  closeModal
}) => {
  const { t, isMobile } = (0, import_react.useContext)(import_ricos_context.RicosContext);
  return /* @__PURE__ */ import_react.default.createElement(
    import_dropdown_modal.DropdownModal,
    {
      title: t("SmartBlock_Toolbar_Orientation_Tooltip"),
      onCloseButtonClick: closeModal,
      options: dropdownOptions.map(
        ({ id, dataHook, label, icon: Icon, iconMobile: IconMobile }) => /* @__PURE__ */ import_react.default.createElement(
          import_list_item_select.ListItemSelect,
          {
            key: id,
            dataHook,
            prefix: isMobile && IconMobile ? /* @__PURE__ */ import_react.default.createElement(IconMobile, null) : Icon ? /* @__PURE__ */ import_react.default.createElement(Icon, null) : null,
            title: label,
            selected: id === selectedId,
            onSelect: () => onSelect(id)
          }
        )
      )
    }
  );
};
//# sourceMappingURL=create-orientation-dropdown-button.js.map
