import { Replace } from "@wix/wix-ui-icons-common";
import React, { useContext, useEffect, useState } from "react";
import { RicosContext } from "./../../../ricos-context/index.js";
import { useModalService } from "./../../../ricos-modals/index.js";
import { ToolbarButton as ToolbarButtonComponent } from "./../../../_shared/toolbar-button/toolbar-button.js";
import { DATA_HOOKS } from "../../data-hooks.js";
const ReplaceShapeButton = ({ toolbarItem }) => {
  const [referenceElement, setReferenceElement] = useState(null);
  const [isActive, setIsActive] = useState(toolbarItem.attributes.active);
  const { isMobile, t } = useContext(RicosContext) || {};
  const modalService = useModalService();
  const onClick = toolbarItem.commands.click;
  useEffect(() => {
    modalService.onModalOpened(() => {
      setIsActive(Boolean(toolbarItem.attributes.active));
    });
    modalService.onModalClosed(() => {
      setIsActive(Boolean(toolbarItem.attributes.active));
    });
  }, [modalService]);
  return /* @__PURE__ */ React.createElement(
    ToolbarButtonComponent,
    {
      prefix: Replace,
      active: isActive,
      onClick: () => onClick({ isMobile, referenceElement }),
      dataHook: DATA_HOOKS.CELL_REPLACE_SHAPE_BUTTON,
      label: t("SmartBlock_CellReplaceShape_Label"),
      ref: setReferenceElement,
      tabIndex: toolbarItem.presentation.tabIndex
    }
  );
};
export {
  ReplaceShapeButton
};
//# sourceMappingURL=replace-shape-button.js.map
