"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_column_size_button_exports = {};
__export(create_column_size_button_exports, {
  createColumnSizeButton: () => createColumnSizeButton
});
module.exports = __toCommonJS(create_column_size_button_exports);
var import_wix_ui_icons_common = require("@wix/wix-ui-icons-common");
var import_react = __toESM(require("react"));
var import_ricos_context = require("./../../ricos-context/index.js");
var import_modal_service_provider = require("./../../ricos-modals/modal-service-provider.js");
var import_create_plugin_toolbar_button = require("./../../_shared/create-plugin-toolbar-button.js");
var import_dropdown_button = require("./../../_shared/dropdown-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_resolvers = require("./resolvers.js");
const SMART_BLOCK_COLUMN_SIZE_DROPDOWN_ID = "smart-block-column-size-dropdown";
const COLUMN_SIZE_OPTIONS = {
  SMALL: {
    label: "SmartBlock_ColumnSize_Small",
    dataHook: import_data_hooks.DATA_HOOKS.COLUMN_SIZE_OPTION_SMALL,
    icon: import_wix_ui_icons_common.DistributeCenterSmall,
    iconMobile: import_wix_ui_icons_common.DistributeCenter
  },
  MEDIUM: {
    label: "SmartBlock_ColumnSize_Medium",
    dataHook: import_data_hooks.DATA_HOOKS.COLUMN_SIZE_OPTION_MEDIUM,
    icon: import_wix_ui_icons_common.DistributeVerticallySmall,
    iconMobile: import_wix_ui_icons_common.DistributeVertically
  },
  LARGE: {
    label: "SmartBlock_ColumnSize_Large",
    dataHook: import_data_hooks.DATA_HOOKS.COLUMN_SIZE_OPTION_LARGE,
    icon: import_wix_ui_icons_common.SizeAndRatioSmall,
    iconMobile: import_wix_ui_icons_common.SizeAndRatio
  },
  EXTRA_LARGE: {
    label: "SmartBlock_ColumnSize_ExtraLarge",
    dataHook: import_data_hooks.DATA_HOOKS.COLUMN_SIZE_OPTION_EXTRA_LARGE,
    icon: import_wix_ui_icons_common.DistributeFullWidthSmall,
    iconMobile: import_wix_ui_icons_common.DistributeFullWidth
  }
};
const getSelectedColumnSize = (selectedNode) => selectedNode?.attrs?.columnSize || "MEDIUM";
const createColumnSizeButton = ({ services }) => (0, import_create_plugin_toolbar_button.createPluginToolbarButton)({
  id: "smartBlockColumnSize",
  type: "dropdown",
  getIcon: ({ attributes }) => COLUMN_SIZE_OPTIONS[getSelectedColumnSize(attributes.selectedNode)].icon,
  tooltip: "SmartBlock_Toolbar_ColumnSize_Tooltip",
  dataHook: import_data_hooks.DATA_HOOKS.COLUMN_SIZE_DROPDOWN_BUTTON,
  attributes: {
    selectedNode: import_resolvers.getSmartBlockNode,
    visible: import_resolvers.isLayoutSelectedAndColumnSizeVariant,
    active: (_, { modals }) => Boolean(modals?.getModal(SMART_BLOCK_COLUMN_SIZE_DROPDOWN_ID))
  },
  renderer: (toolbarItem) => /* @__PURE__ */ import_react.default.createElement(ColumnSizeButton, { toolbarItem, id: SMART_BLOCK_COLUMN_SIZE_DROPDOWN_ID }),
  Component: ColumnSizeDropdown,
  command: (props) => {
    const {
      modals,
      referenceElement,
      getComponentProps,
      tiptapEditor,
      attributes,
      publicCommands
    } = props;
    const selectedNode = attributes.selectedNode;
    if (!selectedNode) {
      return;
    }
    const componentProps = getComponentProps?.({
      tiptapEditor,
      attributes,
      publicCommands,
      t: services.t,
      modals,
      languageDir: services.context.languageDir
    });
    if (!componentProps) {
      return;
    }
    modals.isModalOpen(SMART_BLOCK_COLUMN_SIZE_DROPDOWN_ID) ? modals.closeModal(SMART_BLOCK_COLUMN_SIZE_DROPDOWN_ID) : modals.openModal({
      id: SMART_BLOCK_COLUMN_SIZE_DROPDOWN_ID,
      Component: ColumnSizeDropdown,
      componentProps,
      layout: services.context.isMobile ? "drawer" : "floating",
      positioning: { referenceElement, placement: "bottom" },
      type: "exclusive",
      onClickOutside: {
        on: "pointerup",
        handler: (e) => {
          if (!referenceElement?.contains?.(e.target)) {
            modals.closeModal(SMART_BLOCK_COLUMN_SIZE_DROPDOWN_ID);
            return;
          }
        }
      }
    });
  },
  getComponentProps: ({ tiptapEditor, modals, attributes, t }) => ({
    dropdownOptions: Object.entries(COLUMN_SIZE_OPTIONS).map(([key, option]) => ({
      id: key,
      dataHook: option.dataHook,
      label: t(option.label),
      icon: option.icon,
      iconMobile: option.iconMobile
    })),
    onSelect: (size) => {
      tiptapEditor.commands.setSmartBlockColumnSize(size);
      modals.closeModal(SMART_BLOCK_COLUMN_SIZE_DROPDOWN_ID);
    },
    selectedId: getSelectedColumnSize(attributes.selectedNode),
    closeModal: () => modals.closeModal(SMART_BLOCK_COLUMN_SIZE_DROPDOWN_ID)
  })
});
const ColumnSizeDropdown = ({
  dropdownOptions,
  selectedId,
  closeModal,
  onSelect
}) => {
  const { isMobile, t } = (0, import_react.useContext)(import_ricos_context.RicosContext);
  return /* @__PURE__ */ import_react.default.createElement(
    import_dropdown_modal.DropdownModal,
    {
      onCloseButtonClick: closeModal,
      title: t("SmartBlock_ColumnSize_Title"),
      options: dropdownOptions.map(
        ({ id: commandKey, dataHook, label, icon: Icon, iconMobile: IconMobile }) => /* @__PURE__ */ import_react.default.createElement(
          import_list_item_select.ListItemSelect,
          {
            key: commandKey,
            dataHook,
            prefix: isMobile && IconMobile ? /* @__PURE__ */ import_react.default.createElement(IconMobile, null) : Icon ? /* @__PURE__ */ import_react.default.createElement(Icon, null) : null,
            title: label,
            selected: commandKey === selectedId,
            onClick: () => {
              {
                onSelect(commandKey);
                closeModal();
              }
            }
          }
        )
      )
    }
  );
};
const ColumnSizeButton = ({ toolbarItem, id }) => {
  const isModalOpen = (0, import_modal_service_provider.useModalState)((0, import_modal_service_provider.getIsModalOpen)(id));
  const [referenceElement, setReferenceElement] = (0, import_react.useState)(null);
  const { t } = (0, import_react.useContext)(import_ricos_context.RicosContext);
  const selectedSize = getSelectedColumnSize(toolbarItem?.attributes?.selectedNode);
  return /* @__PURE__ */ import_react.default.createElement(
    import_dropdown_button.DropdownButton,
    {
      dataHook: import_data_hooks.DATA_HOOKS.COLUMN_SIZE_DROPDOWN_BUTTON,
      active: isModalOpen,
      onClick: () => {
        toolbarItem.commands?.click({ referenceElement });
      },
      icon: COLUMN_SIZE_OPTIONS[selectedSize].icon,
      ref: setReferenceElement,
      tooltip: t("SmartBlock_Toolbar_ColumnSize_Tooltip"),
      tabIndex: toolbarItem.presentation.tabIndex
    }
  );
};
//# sourceMappingURL=create-column-size-button.js.map
