"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_text_buttons_exports = {};
__export(get_text_buttons_exports, {
  getTextButtons: () => getTextButtons
});
module.exports = __toCommonJS(get_text_buttons_exports);
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_headings_dropdown_utils = require("./../_shared/headings-dropdown-utils.js");
var import_get_heading_in_selection = require("./../_shared/resolvers/get-heading-in-selection.js");
var import_is_always_visible = require("./../_shared/resolvers/is-always-visible.js");
var import_is_node_or_caption_selected = require("./../_shared/resolvers/is-node-or-caption-selected.js");
var import_is_text_styles_match_document_styles = require("./../_shared/resolvers/is-text-styles-match-document-styles.js");
var import_heading_button_switch = require("./../toolbars-v3/components/buttons/HeadingButtonSwitch/heading-button-switch.js");
var import_data_hooks = require("./data-hooks.js");
var import_get_current_headings_icon = require("./dropdown/get-current-headings-icon.js");
var import_headings_dropdown_lazy = __toESM(require("./dropdown/headings-dropdown-lazy.js"));
var import_headings_dropdown = require("./dropdown/headings-dropdown.js");
const HEADINGS_MODAL_ID = `${import_ricos_types.Node_Type.HEADING}.modal`;
const getTextButtons = (config) => {
  const isCustomHeadings = !!config?.allowHeadingCustomization;
  const id = `${import_ricos_types.Node_Type.HEADING}.dropdown`;
  const attributes = {
    isStylesMatch: import_is_text_styles_match_document_styles.isTextStylesMatchDocumentStylesResolver,
    visible: import_is_always_visible.isAlwaysVisible,
    selectedHeading: import_get_heading_in_selection.getHeadingInSelection,
    disabled: import_is_node_or_caption_selected.isNodeOrCaptionSelected
  };
  const presentation = {
    dataHook: import_data_hooks.TEXT_BUTTON_HEADINGS,
    tooltip: "FormattingToolbar_TextStyleButton_Tooltip",
    getIcon: ({ publicCommands, t }) => {
      return (0, import_get_current_headings_icon.getCurrentHeadingIcon)(isCustomHeadings, publicCommands, t);
    },
    renderer: (toolbarItem) => /* @__PURE__ */ import_react.default.createElement(import_heading_button_switch.HeadingButtonSwitch, { toolbarItem })
  };
  const command = ({ modalService: modals, referenceElement, isMobile }) => () => {
    modals.isModalOpen(HEADINGS_MODAL_ID) ? modals.closeModal(HEADINGS_MODAL_ID) : modals.openModal({
      id: HEADINGS_MODAL_ID,
      Component: isCustomHeadings ? (0, import_headings_dropdown_lazy.default)(216) : (0, import_headings_dropdown_lazy.default)(143),
      componentProps: {},
      positioning: {
        placement: "bottom",
        referenceElement
      },
      layout: isMobile ? "drawer" : referenceElement ? "floating" : "dialog",
      returnFocusToEditor: true
    });
    return true;
  };
  return [
    isCustomHeadings ? {
      id,
      type: "modal",
      presentation,
      attributes,
      command
    } : (0, import_create_text_button.createTextButton)({
      id,
      type: "dropdown",
      presentation: {
        ...presentation,
        id: HEADINGS_MODAL_ID,
        Component: (0, import_headings_dropdown_lazy.default)(143),
        getComponentProps: ({ publicCommands, t, modals }) => {
          const selectedHeading = publicCommands.getCurrentHeading();
          return {
            dropdownOptions: import_headings_dropdown.DEFAULT_HEADERS_DROPDOWN_OPTIONS.map((heading) => ({
              id: import_headings_dropdown.HEADER_TYPE_MAP[heading],
              dataHook: `headings-dropdown-option-${import_headings_dropdown.HEADER_TYPE_MAP[heading]}`,
              label: (0, import_headings_dropdown_utils.translateHeading)(heading, t)
            })),
            onSelect: (heading) => {
              const selectedHeading2 = publicCommands.getCurrentHeading();
              const shouldSetBlockType = selectedHeading2 !== heading;
              shouldSetBlockType && publicCommands.setBlockType(heading);
            },
            selectedId: selectedHeading,
            closeModal: () => modals.closeModal(HEADINGS_MODAL_ID)
          };
        }
      },
      command,
      attributes
    })
  ];
};
//# sourceMappingURL=get-text-buttons.js.map
