import { Objects } 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 AddIconButton = ({ 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: Objects,
      active: isActive,
      onClick: () => onClick({ isMobile, referenceElement }),
      dataHook: DATA_HOOKS.CELL_ADD_ICON_BUTTON,
      label: t("SmartBlock_CellAddShape_Label"),
      ref: setReferenceElement,
      tabIndex: toolbarItem.presentation.tabIndex
    }
  );
};
export {
  AddIconButton
};
//# sourceMappingURL=add-icon-button.js.map
