"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_exports = {};
__export(settings_exports, {
  Settings: () => Settings
});
module.exports = __toCommonJS(settings_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_bi_context_provider = require("./../../../_shared/bi-context-provider/bi-context-provider.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_ui_components = require("./../../../ui-components/index.js");
var import_data_hooks = require("../data-hooks.js");
var import_design_tab = require("./design-tab.js");
var import_layout_tab = require("./layout-tab.js");
const Settings = ({
  nodeId,
  config,
  referenceElement,
  initialTab = "design"
}) => {
  const { t, isMobile } = (0, import_react.useContext)(import_ricos_context.RicosContext);
  const modalService = (0, import_react.useContext)(import_ricos_context.ModalServiceContext) || {};
  const containerEl = (0, import_ui_components.usePanelContainerElement)();
  const { pmNodeAttrs, patchPmNodeAttrs } = (0, import_use_node_attrs.useNodeAttrs)(nodeId, import_pm_node_types.PmNodeType.LAYOUT);
  const [activeTab, setActiveTab] = (0, import_react.useState)(initialTab);
  const logBi = (0, import_bi_context_provider.useBiNext)({ modalId: import_data_hooks.LAYOUT_SETTINGS_MODAL_ID, pluginId: "layout", nodeId });
  const closeModal = () => modalService.closeModal(import_data_hooks.LAYOUT_SETTINGS_MODAL_ID);
  const isColorPickerModalOpen = () => modalService.isModalOpen(import_data_hooks.CELL_SETTINGS_COLOR_PICKER_MODAL_ID);
  (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("Layout settings: node attrs not found"));
    return null;
  }
  return /* @__PURE__ */ import_react.default.createElement(
    import_ui_components.Panel,
    {
      onCloseButtonClick: () => modalService.closeModal(import_data_hooks.LAYOUT_SETTINGS_MODAL_ID),
      dataHook: import_data_hooks.LAYOUT_SETTINGS_MODAL_ID,
      maxHeight: isMobile ? void 0 : 590
    },
    /* @__PURE__ */ import_react.default.createElement(import_ui_components.PanelHeader, { title: t("Layout_SettingsModal_Header") }),
    /* @__PURE__ */ import_react.default.createElement(
      import_design_system.Tabs,
      {
        dataHook: import_data_hooks.LAYOUT_SETTINGS_TABS,
        size: "small",
        alignment: "center",
        type: "uniformFull",
        minWidth: 0,
        activeId: activeTab,
        onClick: (value) => {
          setActiveTab(value.id);
          logBi({ dataHook: import_data_hooks.LAYOUT_SETTINGS_TABS, value: value.id });
        },
        items: [
          { id: "design", title: t("Layout_SettingsModal_Tab_Design") },
          { id: "layout", title: t("Layout_SettingsModal_Tab_Layout") }
        ]
      }
    ),
    (() => {
      switch (activeTab) {
        case "design":
          return /* @__PURE__ */ import_react.default.createElement(
            import_design_tab.DesignTab,
            {
              pmNodeAttrs,
              patchPmNodeAttrs,
              nodeId,
              config
            }
          );
        case "layout":
          return /* @__PURE__ */ import_react.default.createElement(
            import_layout_tab.LayoutTab,
            {
              nodeId,
              pmNodeAttrs,
              patchPmNodeAttrs
            }
          );
        default:
          return null;
      }
    })()
  );
};
//# sourceMappingURL=settings.js.map
