"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 settings_modal_exports = {};
__export(settings_modal_exports, {
  ButtonSettingsModal: () => ButtonSettingsModal
});
module.exports = __toCommonJS(settings_modal_exports);
var import_react = __toESM(require("react"));
var import_ricos_context = require("./../../ricos-context/index.js");
var import_bi_context_provider = require("./../../_shared/bi-context-provider/bi-context-provider.js");
var import_use_node_attrs = require("./../../_shared/use-node-attrs.js");
var import_ui_components = require("./../../ui-components/index.js");
var import_constants = require("../constants.js");
var import_types = require("../types.js");
var import_settings_modal_content = require("./settings-modal-content.js");
const ButtonSettingsModal = ({
  nodeId,
  settings,
  type,
  modalId,
  activeTab: tab,
  referenceElement
}) => {
  const modalService = (0, import_react.useContext)(import_ricos_context.ModalServiceContext) || {};
  const containerEl = (0, import_ui_components.usePanelContainerElement)();
  const nodeType = type === import_types.LINK_BUTTON_TYPE ? "LINK_BUTTON" : "ACTION_BUTTON";
  const logBi = (0, import_bi_context_provider.useBiNext)({
    modalId: import_constants.buttonsModals.settings[type],
    pluginId: nodeType === "LINK_BUTTON" ? "linkButton" : "actionButton",
    nodeId
  });
  const { patchPmNodeAttrs, pmNodeAttrs } = (0, import_use_node_attrs.useNodeAttrs)(nodeId, nodeType);
  const [activeTab, setActiveTab] = (0, import_react.useState)(tab ?? import_constants.SETTINGS_TAB.SETTINGS);
  const handleOnChange = (data) => patchPmNodeAttrs?.(data);
  const isColorPickerModalOpen = () => modalService.isModalOpen(import_constants.buttonsModals.colorPicker);
  const closeModal = () => modalService.closeModal(modalId);
  (0, import_ui_components.useClickOutside)({
    containerRef: { current: containerEl },
    onClickOutside: (e) => {
      const target = e.target;
      if (referenceElement?.contains(target)) {
        return;
      }
      closeModal();
    },
    disable: isColorPickerModalOpen()
  });
  return pmNodeAttrs ? /* @__PURE__ */ import_react.default.createElement(
    import_settings_modal_content.SettingsModalContent,
    {
      buttonData: pmNodeAttrs,
      config: settings,
      onClose: closeModal,
      onChange: handleOnChange,
      nodeId,
      nodeType,
      activeTab,
      onTabChange: setActiveTab,
      logBi
    }
  ) : null;
};
//# sourceMappingURL=settings-modal.js.map
