"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, {
  SettingsModal: () => SettingsModal
});
module.exports = __toCommonJS(settings_modal_exports);
var import_design_system = require("@wix/design-system");
var import_react = __toESM(require("react"));
var import_ricos_context = require("./../../ricos-context/index.js");
var import_log_invariant = require("./../../_shared/log-invariant.js");
var import_pm_node_types = require("./../../_shared/pm-node-types.js");
var import_use_node_attrs = require("./../../_shared/use-node-attrs.js");
var import_data_hooks = require("./../../plugin-link-preview/data-hooks.js");
var import_ui_components = require("./../../ui-components/index.js");
var import_consts = require("../consts.js");
var import_settings_modal_scss = __toESM(require("../statics/styles/settings-modal-scss.js"));
var import_design_tab = require("./design-tab.js");
var import_settings_tab = require("./settings-tab.js");
const SettingsModal = ({
  nodeId,
  activeTab,
  config,
  referenceElement
}) => {
  const modalService = (0, import_react.useContext)(import_ricos_context.ModalServiceContext) || {};
  const containerEl = (0, import_ui_components.usePanelContainerElement)();
  const { t, isMobile } = (0, import_react.useContext)(import_ricos_context.RicosContext);
  const [activeId, setActiveId] = (0, import_react.useState)(activeTab);
  const { pmNodeAttrs, patchPmNodeAttrs } = (0, import_use_node_attrs.useNodeAttrs)(nodeId, import_pm_node_types.PmNodeType.LINK_PREVIEW);
  const isColorPickerModalOpen = () => modalService.isModalOpen(import_consts.linkPreviewModals.colorPicker);
  const closeModal = () => modalService.closeModal(import_consts.linkPreviewModals.settings);
  (0, import_ui_components.useClickOutside)({
    containerRef: { current: containerEl },
    onClickOutside: (e) => {
      const target = e.target;
      if (referenceElement?.contains(target)) {
        return;
      }
      closeModal();
    },
    disable: isColorPickerModalOpen()
  });
  if (!pmNodeAttrs) {
    (0, import_log_invariant.logInvariant)(new Error("Link preview settings: node attrs not found"));
    return null;
  }
  return /* @__PURE__ */ import_react.default.createElement("div", { className: import_settings_modal_scss.default.modal }, /* @__PURE__ */ import_react.default.createElement(
    import_ui_components.Panel,
    {
      closeButtonProps: { onClick: () => modalService.closeModal(import_consts.linkPreviewModals.settings) },
      dataHook: import_data_hooks.SETTINGS_LINKPREVIEW_MODAL,
      maxHeight: isMobile ? void 0 : 590
    },
    /* @__PURE__ */ import_react.default.createElement(import_ui_components.PanelHeader, { title: t("LinkPreview_Design_Panel_Header") }),
    /* @__PURE__ */ import_react.default.createElement(
      import_design_system.Tabs,
      {
        dataHook: import_data_hooks.SETTINGS_LINKPREVIEW_TABS,
        size: "small",
        alignment: "center",
        type: "uniformFull",
        minWidth: 0,
        activeId,
        onClick: (value) => setActiveId(value.id),
        items: [
          { id: "settings", title: t("LinkPreview_Design_Panel_Tab_Layout") },
          { id: "design", title: t("LinkPreview_Design_Panel_Tab_Design") }
        ]
      }
    ),
    activeId === "settings" && /* @__PURE__ */ import_react.default.createElement(import_settings_tab.SettingsTab, { nodeId }),
    activeId === "design" && /* @__PURE__ */ import_react.default.createElement(
      import_design_tab.DesignTab,
      {
        nodeId,
        config,
        modalId: import_consts.linkPreviewModals.settings,
        pmNodeAttrs,
        patchPmNodeAttrs
      }
    )
  ));
};
//# sourceMappingURL=settings-modal.js.map
