import { ChevronDownSmall } from "@wix/wix-ui-icons-common";
import React, { useContext, useState } from "react";
import { EditorContext, RicosContext } from "./../../../../ricos-context/index.js";
import { getIsModalOpen, useModalState } from "./../../../../ricos-modals/modal-service-provider.js";
import { Node_Type } from "./../../../../ricos-schema/legacy/wix/rich_content/v1/index.js";
import { getCustomHeadingsLabel } from "./../../../../_shared/headings-dropdown-utils.js";
import { ToolbarButton } from "./../../../../_shared/toolbar-button/toolbar-button.js";
const CustomHeadingButton = ({
  toolbarItem,
  dataHook
}) => {
  const { getPublicCommands } = useContext(EditorContext);
  const { t } = useContext(RicosContext);
  const isModalOpen = useModalState(getIsModalOpen(`${Node_Type.HEADING}.modal`));
  const [referenceElement, setReferenceElement] = useState(null);
  const publicCommands = getPublicCommands?.();
  const selectedHeading = toolbarItem.attributes.selectedHeading;
  const Label = getCustomHeadingsLabel(selectedHeading, t, publicCommands);
  const tooltip = t(toolbarItem.presentation?.tooltip);
  return /* @__PURE__ */ React.createElement(
    ToolbarButton,
    {
      ref: setReferenceElement,
      disabled: toolbarItem.attributes.disabled,
      active: isModalOpen,
      onClick: (e) => toolbarItem.commands?.click({ referenceElement, clickFromKeyboard: !e.detail }),
      ariaLabel: tooltip,
      label: Label,
      suffix: ChevronDownSmall,
      dataHook,
      tabIndex: toolbarItem.presentation.tabIndex
    }
  );
};
export {
  CustomHeadingButton
};
//# sourceMappingURL=custom-heading-button.js.map
