"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 heading_button_exports = {};
__export(heading_button_exports, {
  HeadingButton: () => HeadingButton
});
module.exports = __toCommonJS(heading_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_v1 = require("./../../../../ricos-schema/legacy/wix/rich_content/v1/index.js");
var import_headings_dropdown_utils = require("./../../../../_shared/headings-dropdown-utils.js");
var import_toolbar_button = require("./../../../../_shared/toolbar-button/toolbar-button.js");
var import_HeadingButton_scss = __toESM(require("./HeadingButton-scss.js"));
const HeadingButton = ({
  toolbarItem,
  dataHook
}) => {
  const { t } = (0, import_react.useContext)(import_ricos_context.RicosContext);
  const isModalOpen = (0, import_modal_service_provider.useModalState)((0, import_modal_service_provider.getIsModalOpen)(`${import_v1.Node_Type.HEADING}.modal`));
  const [referenceElement, setReferenceElement] = (0, import_react.useState)(null);
  const selectedHeading = toolbarItem.attributes.selectedHeading;
  const Label = (0, import_headings_dropdown_utils.translateHeading)(import_headings_dropdown_utils.headingsMap[selectedHeading], t);
  const prefix = import_react.default.useCallback(() => {
    return /* @__PURE__ */ import_react.default.createElement("span", { className: import_HeadingButton_scss.default.headingButtonContent }, Label, /* @__PURE__ */ import_react.default.createElement(import_wix_ui_icons_common.ChevronDownSmall, null));
  }, [Label]);
  const tooltip = t(toolbarItem.presentation?.tooltip);
  return /* @__PURE__ */ import_react.default.createElement(
    import_toolbar_button.ToolbarButton,
    {
      ref: setReferenceElement,
      disabled: toolbarItem.attributes.disabled,
      active: isModalOpen,
      tooltip,
      onClick: (e) => toolbarItem.commands?.click({ referenceElement, clickFromKeyboard: !e.detail }),
      prefix,
      dataHook,
      tabIndex: toolbarItem.presentation.tabIndex
    }
  );
};
//# sourceMappingURL=heading-button.js.map
